Skip to main content

hatch-vcs

CI/CD CI - Test CD - Build
Package PyPI - Version PyPI - Python Version
Meta Hatch project code style - black types - Mypy License - MIT GitHub Sponsors

This provides a plugin for Hatch that uses your preferred version control system (like Git) to determine project versions.

Table of Contents

Global dependency

Ensure hatch-vcs is defined within the build-system.requires field in your pyproject.toml file.

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

Version source

The version source plugin name is vcs.

  • pyproject.toml

    [tool.hatch.version]
    source = "vcs"
    
  • hatch.toml

    [version]
    source = "vcs"
    

Version source options

Option Type Default Description
tag-pattern str see code A regular expression used to extract the version part from VCS tags. The pattern needs to contain either a single match group, or a group named version, that captures the actual version information.
fallback-version str The version that will be used if no other method for detecting the version is successful. If not specified, unsuccessful version detection will raise an error.
raw-options dict A table of setuptools-scm parameters that will override any of the options listed above. The write_to and write_to_template parameters are ignored.

Version source environment variables

  • SETUPTOOLS_SCM_PRETEND_VERSION: When defined and not empty, it's used as the primary source for the version, in which case it will be an unparsed string.

Build hook

The build hook plugin name is vcs.

  • pyproject.toml

    [tool.hatch.build.hooks.vcs]
    version-file = "_version.py"
    
  • hatch.toml

    [build.hooks.vcs]
    version-file = "_version.py"
    

Building or installing when the latest tag is v1.2.3 will generate the file

  • _version.py

    # coding: utf-8
    # file generated by setuptools_scm
    # don't change, don't track in version control
    __version__ = version = '1.2.3'
    __version_tuple__ = version_tuple = (1, 2, 3)
    

Build hook options

Option Type Default Description
version-file str REQUIRED The relative path to the file that gets updated with the current version.
template str The template used to overwrite the version-file. See the code for the default template for each file extension.

Editable installs

The version file is only updated upon install or build. Thus the version number in an editable install (Hatch's dev mode) will be incorrect if the version changes and the project is not rebuilt. An unsupported workaround for keeping the version number up-to-date can be found at hatch-vcs-footgun-example.

Metadata hook

Note: only Git is supported

The metadata hook plugin name is vcs.

  • pyproject.toml

    [tool.hatch.metadata.hooks.vcs]
    
  • hatch.toml

    [metadata.hooks.vcs]
    

Metadata hook options

URLs

The urls option is equivalent to project.urls except that each URL supports context formatting with the following fields:

  • commit_hash - the latest commit hash

Example

  • pyproject.toml

    [tool.hatch.metadata.hooks.vcs]
    Homepage = "https://www.example.com"
    source_archive = "https://github.com/org/repo/archive/{commit_hash}.zip"
    
  • hatch.toml

    [metadata.hooks.vcs]
    Homepage = "https://www.example.com"
    source_archive = "https://github.com/org/repo/archive/{commit_hash}.zip"
    

License

hatch-vcs is distributed under the terms of the MIT license.

Metadata

Release files for hatch-vcs 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hatch-vcs 0.3.0
File Size Uploaded
hatch_vcs-0.3.0.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hatch-vcs 0.3.0
File Interpreter ABI Platform
hatch_vcs-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / hatch_vcs-0.3.0.tar.gz

Download URL hatch_vcs-0.3.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cec5107cfce482c67f8bc96f18bbc320c9aa0d068180e14ad317bbee5a153fee
BLAKE2b-256 checksum
How to use checksums
0433b68d68e532392d938472d16a03e4ce0ccd749ea31b42d18f8baa6547cbfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / hatch_vcs-0.3.0-py3-none-any.whl

Download URL hatch_vcs-0.3.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60ce59a3fa4664057e4a858b6a96ab0b9dec21bf8f562f836139315bb361be8c
BLAKE2b-256 checksum
How to use checksums
00b190cc7881c2e870333eeafa6afb7b27de53418aad1ba5409ad331c96608a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page