Versioneer

0.29 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

Versioneer itself is a tool to *manage* your project's version, not a library meant for direct runtime consumption in most application code beyond obtaining the `__version__` string. The primary use involves running `versioneer install` in your project's root, configuring `setup.cfg` or `pyproject.toml`, and then modifying `setup.py` (if applicable). This setup creates a `_version.py` file in your package (e.g., `src/your_package/_version.py`) which defines `get_versions()`. Your `__init__.py` then typically imports and uses this to set `__version__`. The code snippet demonstrates how the version string would be retrieved in a Python module after Versioneer has been set up.

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__}")

view raw JSON →