vcver - Dynamic Versioning from VCS
vcver is a Python library that automates the generation of package version strings by extracting information directly from version control systems such as Git or Mercurial. This enables dynamic versioning based on commit hashes, tags, and branch names, particularly useful for development builds. It seamlessly integrates with `setuptools` and is actively maintained with releases occurring roughly annually. The current version is 0.2.12.
Warnings
- gotcha vcver relies on Git or Mercurial being installed and accessible in the system's PATH. If the repository is not a valid Git/Mercurial repository or the VCS tools are not found, `vcver.get_version()` will fall back to a default (e.g., '0.0.0') or raise an error depending on configuration.
- gotcha When running in environments where `.git` or `.hg` directories are not present (e.g., installed packages from PyPI, CI/CD environments that don't clone full history), `vcver.get_version()` might not produce the expected dynamic version. For release builds, consider using `vcver.set_version()` to explicitly embed a fixed version.
Install
-
pip install vcver
Imports
- get_version
import vcver version = vcver.get_version()
Quickstart
import vcver
# Example usage in setup.py for setuptools:
# from setuptools import setup
# setup(
# name='your_package',
# version=vcver.get_version(),
# # ... other setup arguments
# )
# Or to get the version directly:
current_version = vcver.get_version()
print(f"Current package version: {current_version}")