Skip to main content

Adds a command to dynamically get the version from the VCS of choice

Project description

Get version from version control instead of hardcoding it into setup.py

introduction

Instead of hardcoding the version in setup.py like 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 into some-dist-name.egg-info/version.txt, so that the version can also be found if setup.py is being run from an sdist or something.

When it can find the version from either some-dist-name.egg-info/version.txt or the output of the version_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 keyword

Instead of specifying the version keyword argument, specify the version_command keyword 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 example git describe. If it’s a tuple, it must have two or three elements, and have the form (command, pep440_mode[, post_mode]).

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. pip and setuptools will throw warnings.

pep440_mode = "pep440-git-local":

Moves number of commits and hash as local identifier:

  • Change 1.2.3 to 1.2.3

  • Change 1.2.3-10-abc1234 to 1.2.3+git-10-abc1234

pep440_mode = "pep440-git-dev":

(Deprecated) Adds rhe number of commits since a git tag as a .dev tag:

  • Change 1.2.3-N-abc1234 to 1.2.3.devN

This 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.

  • Leave 1.2.3.dev and 1.2.3.dev0 as they are

  • Change 1.2.3.dev-N-abc1234 to 1.2.3.devN

  • Change 1.2.3a-N-ab1234 to 1.2.3aN

  • Change 1.2.3 to 1.2.3

  • Change 1.2.3-10-abcd123 to 1.2.3.post10, or 1.2.3-rev10, as you prefer

In 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.

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 of 1.2a3-4-abcd123:

  • ".post" gives 1.2a3.post4

  • ".rev_" gives 1.2a3.rev_4

  • "-" gives 1.2a3-4

installation

To use it, just do this:

pip install setuptools-version-command

With the pip of the global python. (Or use --user.)

testing

To test it, run ./setup.py --version.

developing

Within a checkout of this repo:

virtualenv env
env/bin/pip install --editable .
env/bin/python setup.py --version

Make sure that you change the setup.py so that it actually makes use of setuptools-version-command.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

setuptools-version-command-2.1a0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

setuptools_version_command-2.1a0-py2-none-any.whl (7.9 kB view details)

Uploaded Python 2

File details

Details for the file setuptools-version-command-2.1a0.tar.gz.

File metadata

File hashes

Hashes for setuptools-version-command-2.1a0.tar.gz
Algorithm Hash digest
SHA256 7eb49637027e5b2f93697e54ba63c94b9e4167f086fd85c39f1e277c4f34960b
MD5 1fd676a0167dd28d31b7a608fd1c8fca
BLAKE2b-256 b8cf8bce48a05aa9d4017a2d5965227781f7f9a514dabbb7ea7bc14b5e66cc94

See more details on using hashes here.

File details

Details for the file setuptools_version_command-2.1a0-py2-none-any.whl.

File metadata

File hashes

Hashes for setuptools_version_command-2.1a0-py2-none-any.whl
Algorithm Hash digest
SHA256 29959a0bfcca1577bededc9e7c1875a47637f0524b7a4c4966b4ecdc48bdd52f
MD5 7f6563f0b4ab822b58b1aef0db5a96fd
BLAKE2b-256 d560f735c7a37e26b2274a011d5710ad2b05494952b5eaf1c43a4dadf69b1d1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page