Package: setuptools-version-command
Get version from version control instead of hardcoding it into setup.py⚠ DEPRECATION NOTICE ⚠This package is no longer maintained. It will not evolve along with the Python
packaging ecosystem. Specifically, as of November 2021, it will not work with
static metadata defined insetup.cfgas opposed to metadata defined insetup.py.There is a good alternative: usesetuptools-scminstead. This is easy to
set up in asetup.cfg, see the PyPAPackaging Python projectstutorial.introductionInstead of hardcoding the version insetup.pylike this:setup(name='some-dist-name',version='1.0',...)This package allows specifying a VCS command like this:setup(name='some-dist-name',version_command='git describe',...)…Which will then update the version intosome-dist-name.egg-info/version.txt, so that the version can also be found
ifsetup.pyis being run from an sdist or something.When it can find the version from eithersome-dist-name.egg-info/version.txtor the output of theversion_command, it will update the version key that is normally used for
the version, such as what’s used in the sdist filename and so on.setup keywordInstead of specifying theversionkeyword argument, specify theversion_commandkeyword argument. It can either be a str or a tuple. If
it’s a str, it’s interpreted as just the command to execute, for examplegit describe. If it’s a tuple, it must have two or three elements, and have the
form(command, pep440_mode[, post_mode]).pep440_modecan only be
specified in the tuple ofversion_argument, not as separate
argument ofsetup.A list of possible values for tuples passed to theversion_commandkeyword
argument:command:Must be"git describe", but could also support other VCS in
the future.pep440_mode=None:Takes output of command as is, so ignores PEP440.pipandsetuptoolswill throw warnings.pep440_mode="pep440-git-local":Moves number of commits and hash as
local identifier:Change1.2.3to1.2.3Change1.2.3-10-abc1234to1.2.3+git-10-abc1234pep440_mode="pep440-git-dev":(Deprecated) Adds rhe number of
commits since a git tag as a .dev tag:Change1.2.3-N-abc1234to1.2.3.devNThis is against PEP440-specification and supported only for backwards
compatibility. It may be removed in time.pep440_mode="pep440-git":Works with pre-release versions (alpha,
beta, rc etc), post-release versions (post, rev, etc) and dev versions.Leave1.2.3.devand1.2.3.dev0as they areChange1.2.3.dev-N-abc1234to1.2.3.devNChange1.2.3a-N-ab1234to1.2.3aNChange1.2.3to1.2.3Change1.2.3-10-abcd123to1.2.3.post10, or1.2.3-rev10, as
you preferIn other words, a tag can be absent, open (implicitly or explicitly 0), or
closed (have a number greater than zero). If the last Git tag is an open
dev tag, that’s the one that will be used for the revision number. If the
last Git tag is an open post-release tag, then that will be used. If the
last Git tag is an open pre-release tag, that will be used. In other cases,
a post-release tag will be added.pep440_mode="pep440-git-full:Similar to"pep440-git"but
includes the commit hash and dirty marker (if present) in the local version
portion.Change1.2.3.dev-N-abc1234to1.2.3.devN+gabc1234Change1.2.3-dirtyto1.2.3+dirtyChange1.2.3-10-abcd123-dirtyto1.2.3.post10+gabcd123.dirtyThe inclusion of the hash in the local identifier helps avoid ambiguity
between two versions that are the same number of commits from the latest
tag.The inclusion of the dirty flag (which requirescommandvalue to
include the--dirtyoption) ensures that local uncommitted changes
are considered newer than the last set of committed changes.post_mode:Template for adding post-release tags. Optional separator (dot,
dash or underscore), followed by"post","rev"or"r", followed
by another optional separator. Can also be a single dash. Default is".post".Given a git describe output of1.2a3-4-abcd123:".post"gives1.2a3.post4".rev_"gives1.2a3.rev_4"-"gives1.2a3-4installationTo use it, just do this:pipinstallsetuptools-version-commandWith the pip of the global python. (Or use--user.)testingTo test it, run./setup.py--version.developingWithin a checkout of this repo:virtualenvenvenv/bin/pipinstall--editable.env/bin/pythonsetup.py--versionMake sure that you change thesetup.pyso that it actually makes use of
setuptools-version-command.