Skip to main content

Versioning It with your Version In Git

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions Conda Version MIT License

GitHub | PyPI | Documentation | Issues | Changelog

versioningitVersioning It with your Version In Git

versioningit is yet another Python packaging plugin for automatically determining your package’s version based on your version control repository’s tags. Unlike others, it allows easy customization of the version format and even lets you easily override the separate functions used for version extraction & calculation.

Features:

  • Works with both setuptools and Hatch

  • Installed & configured through PEP 518’s pyproject.toml

  • Supports Git, modern Git archives, and Mercurial

  • Formatting of the final version uses format template strings, with fields for basic VCS information and separate template strings for distanced vs. dirty vs. distanced-and-dirty repository states

  • Can optionally write the final version and other details to a file for loading at runtime

  • Provides custom hooks for inserting the final version and other details into a source file at build time

  • The individual methods for VCS querying, tag-to-version calculation, version bumping, version formatting, and writing the version to a file can all be customized using either functions defined alongside one’s project code or via publicly-distributed entry points

  • Can alternatively be used as a library for use in setup.py or the like, in case you don’t want to or can’t configure it via pyproject.toml

  • The only thing it does is calculate your version and optionally write it to a file; there’s no overriding of your sdist contents based on what’s in your Git repository, especially not without a way to turn it off, because that would just be rude.

Installation & Setup

versioningit requires Python 3.8 or higher. Just use pip for Python 3 (You have pip, right?) to install versioningit and its dependencies:

python3 -m pip install versioningit

However, usually you won’t need to install versioningit in your environment directly. Instead, you specify it in your project’s pyproject.toml file in the build-system.requires key, like so:

# If using Setuptools:
[build-system]
requires = [
    "setuptools",
    "versioningit",
]
build-backend = "setuptools.build_meta"

# If using Hatch:
[build-system]
requires = [
    "hatchling",
    "versioningit",
]
build-backend = "hatchling.build"

# This setting is also required if you're using Hatch:
[tool.hatch.version]
source = "versioningit"

Then, you configure versioningit by adding a [tool.versioningit] table to your pyproject.toml. See the documentation for details, but you can get up & running with just the minimal configuration, an empty table:

[tool.versioningit]

versioningit eliminates the need to list an explicit version in setup.py, setup.cfg, or pyproject.toml (and any explicit version you do list will be ignored when using versioningit), so you should remove any such settings in order to reduce confusion.

Note: If you’re specifying your project metadata via a [project] table in pyproject.toml, you need to set project.dynamic = ["version"] in order for versioningit to work.

Once you have a [tool.versioningit] table in your pyproject.toml — and once your repository has at least one tag — building your project with build or similar will result in your project’s version automatically being set based on the latest tag in your Git repository. You can test your configuration and see what the resulting version will be using the versioningit command (see the documentation).

Example Configurations

One of versioningit’s biggest strengths is its ability to configure the version format using placeholder strings. The default format configuration looks like this:

[tool.versioningit.format]
# Format used when there have been commits since the most recent tag:
distance = "{base_version}.post{distance}+{vcs}{rev}"
# Example formatted version: 1.2.3.post42+ge174a1f

# Format used when there are uncommitted changes:
dirty = "{base_version}+d{build_date:%Y%m%d}"
# Example formatted version: 1.2.3+d20230922

# Format used when there are both commits and uncommitted changes:
distance-dirty = "{base_version}.post{distance}+{vcs}{rev}.d{build_date:%Y%m%d}"
# Example formatted version: 1.2.3.post42+ge174a1f.d20230922

Other format configurations of interest include:

  • The default format used by setuptools_scm:

    [tool.versioningit.next-version]
    method = "smallest"
    
    [tool.versioningit.format]
    distance = "{next_version}.dev{distance}+{vcs}{rev}"
    # Example formatted version: 1.2.4.dev42+ge174a1f
    
    dirty = "{base_version}+d{build_date:%Y%m%d}"
    # Example formatted version: 1.2.3+d20230922
    
    distance-dirty = "{next_version}.dev{distance}+{vcs}{rev}.d{build_date:%Y%m%d}"
    # Example formatted version: 1.2.4.dev42+ge174a1f.d20230922
  • The format used by versioneer:

    [tool.versioningit.format]
    distance = "{base_version}+{distance}.{vcs}{rev}"
    # Example formatted version: 1.2.3+42.ge174a1f
    
    dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
    # Example formatted version: 1.2.3+42.ge174a1f.dirty
    
    distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
    # Example formatted version: 1.2.3+42.ge174a1f.dirty
  • The format used by vcversioner:

    [tool.versioningit.format]
    distance = "{base_version}.post{distance}"
    # Example formatted version: 1.2.3.post42
    
    dirty = "{base_version}"
    # Example formatted version: 1.2.3
    
    distance-dirty = "{base_version}.post{distance}"
    # Example formatted version: 1.2.3.post42

Download files

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

Source Distribution

versioningit-3.1.3.tar.gz (213.3 kB view details)

Uploaded Source

Built Distribution

versioningit-3.1.3-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file versioningit-3.1.3.tar.gz.

File metadata

  • Download URL: versioningit-3.1.3.tar.gz
  • Upload date:
  • Size: 213.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for versioningit-3.1.3.tar.gz
Algorithm Hash digest
SHA256 1b7f3c2d3e9c7b737e7d2664c3445a61a121e3de7610e8e781b483f5d88e3618
MD5 b8d9f4dbd0a244ca1e53ce302673455f
BLAKE2b-256 af5b8f4acd9a691755a20ee21fadab0045243e9aef3f5efcc0977c338c140eb5

See more details on using hashes here.

File details

Details for the file versioningit-3.1.3-py3-none-any.whl.

File metadata

  • Download URL: versioningit-3.1.3-py3-none-any.whl
  • Upload date:
  • Size: 38.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for versioningit-3.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 760decf2b6b72d6bb83900949d0dff3260dab9a4ea33d29da66d5f1a2ddcafe9
MD5 0eab1227ebfd59863c63686d961416e3
BLAKE2b-256 3192f379b5c04c6539568ae6fd3ae4ba52c26cbaec7cbe4734ab4e97edd0f213

See more details on using hashes here.

Supported by

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