Versioneer
Versioneer is a Python tool that provides easy, VCS-based management of project version strings for setuptools-based projects. It aims to automate the process of updating version numbers, making releases as simple as creating a new VCS tag. It is actively maintained with regular releases, currently at version 0.29.
Warnings
- breaking Versioneer dropped official support for Python 3.6 in version 0.23, and removed old `distutils` hacks. Users on Python 3.6 or older `setuptools`/`distutils` versions may encounter issues or compilation failures.
- gotcha Versioneer defaults to `0+unknown` if it cannot correctly determine the version string from your VCS (e.g., Git) or if there are problems during its lookup. This can happen with `pip install .` from subproject directories or misconfigured VCS repositories.
- gotcha Versioneer has limited support for source trees where `setup.py` (or `pyproject.toml` in newer versions) is not in the root directory alongside your VCS (`.git`) directory, especially in multi-subproject layouts.
- breaking When configuring Versioneer via `pyproject.toml` in 'build-time dependency mode' (using `--no-vendor`), older versions of Versioneer may incorrectly complain about a missing `setup.py`. While version 0.29 improved support for `pyproject.toml`-only projects, older versions expected `setup.py` to be present.
Install
-
pip install versioneer
Imports
- get_versions
from your_package_name._version import get_versions __version__ = get_versions()['version']
- versioneer.get_version, versioneer.get_cmdclass
import versioneer setup( version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), # ... other setup arguments )
Quickstart
import os
# --- After Versioneer setup (via `versioneer install`) ---
# Assume versioneer has been correctly set up in a project,
# creating _version.py and modifying __init__.py
# Example of how the version is accessed in your package's __init__.py
# (The `get_versions` function is generated by Versioneer in _version.py)
# Simulate a _version.py and __init__.py setup for demonstration
# In a real project, these files would be managed by Versioneer.
_versioneer_data = {
'version': os.environ.get('TEST_VERSION', '0.0.1+test.gdeadbeef.dirty'),
'full-revisionid': 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
'dirty': True,
'error': None
}
def get_versions_mock():
return _versioneer_data
# In your actual package's __init__.py, after `versioneer install`:
# from ._version import get_versions
# __version__ = get_versions()['version']
# For this example, we'll use our mock:
__version__ = get_versions_mock()['version']
print(f"The package version is: {__version__}")
# To see how it changes without a dirty tag:
os.environ['TEST_VERSION'] = '1.2.3'
__version__ = get_versions_mock()['version']
print(f"The package version (clean) is: {__version__}")