🧙 version-wizard¶
The version wizard extracts version information from a git tag and includes it in your python package so you don’t have to worry about commit messages like Bump version to 0.8.1
anymore. Here’s how to use the wizard:
Install by running
pip install version-wizard
.Add
include VERSION
to yourMANIFEST.in
file (or create one by runningecho "include VERSION" > MANIFEST.in
).Update your
setup.py
as shown below.Push semantic versioning tags to your GitHub branch, e.g,
0.8.1
.
# setup.py
from setuptools import setup, ...
from version_wizard import from_github_tag
setup(
version=from_github_tag(),
...
)
Behind the scenes¶
The call to from_github_tag
will do one of two things:
If the
VERSION
file exists, it simply returns its contents. This is the typical behavior when your installing the package from pypi, for example.If the
VERSION
file does not exist, it will try to extract the version from theGITHUB_REF
environment variable and write it to theVERSION
file.
Because the MANIFEST.in
includes VERSION
, the VERSION
file will be included in any distribution, e.g., when you run python setup.py sdist
. The correct version is thus automatically packaged with your distribution elminiating any possible inconsistencies.
Interface¶
- version_wizard.from_github_tag(default: str = '0.0.0+dev', version_file: str = 'VERSION', version_pattern: str = '\\d+\\.\\d+\\.\\d+', check_manifest: bool = True, manifest_file: str = 'MANIFEST.in') str ¶
Load the version from the version file if it exists. Otherwise, get the version from a GitHub tag reference and write it to the version file.
- Parameters:
default – Default version if a github tag reference is not available.
version_file – File to load the version from or write the version to.
version_pattern – Pattern of the version to extract from the GitHub tag reference.
check_manifest – Whether to verify that the version_file is included by manifest_file.
manifest_file – File encoding the package manifest.
- Returns:
The package version.