Hatch VCS Plugin

0.5.0 · active · verified Sun Apr 05

Hatch-vcs is a Hatch plugin that enables project versioning using your preferred Version Control System (VCS), such as Git or Mercurial. It integrates with Hatch's build system to dynamically determine the package version based on VCS tags. The current version is 0.5.0, and it maintains an active release cadence, frequently updating to support new Python versions and Hatchling features.

Warnings

Install

Imports

Quickstart

This configuration in `pyproject.toml` sets up `hatch-vcs` to derive your package's version from Git tags. It also specifies a `_version.py` file to be generated at build time, ensuring a static version is available in your distribution. The `project.dynamic` field should include `"version"` to enable dynamic versioning.

# pyproject.toml
[project]
name = "my-package"
version = "0.0.1" # This is a fallback/initial value, will be overridden by VCS
dynamic = ["version"]

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

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

[tool.hatch.build.hooks.vcs]
version-file = "src/my_package/_version.py"

# Example of how you might read the version in your package (e.g., in src/my_package/__init__.py)
# from importlib.metadata import version
# try:
#     __version__ = version("my-package")
# except Exception:
#     # Fallback for development installs or if metadata is not yet available
#     __version__ = "0.0.0+unknown"

view raw JSON →