chore: switch to hatch-vcs for tag-driven dynamic versioning#98
Merged
Conversation
Replace the hand-maintained '[project].version' in pyproject.toml with hatch-vcs so the package version is derived solely from git tags (v*). - pyproject.toml: declare 'dynamic = ["version"]', add hatch-vcs as a build requirement, configure '[tool.hatch.version]' with source = vcs, and emit 'src/haclient/_version.py' via the vcs build hook. - haclient/__init__.py: prefer the generated '_version.py'; fall back to importlib.metadata, then '0.0.0+unknown' for source checkouts. - .gitignore: ignore the generated 'src/haclient/_version.py'. - CI workflows: set 'fetch-depth: 0' on checkout so hatch-vcs can read tags during install/build (lint, typecheck, tests, build, release). - ruff/mypy: exclude the generated _version.py from formatting/typecheck. - tests/test_packaging.py: replace the static-equality assertion with invariants for dynamic versioning (no literal release version in __init__.py, 'dynamic' declared in pyproject.toml, metadata present). Releases are now cut by tagging 'vX.Y.Z'; untagged commits produce PEP 440 dev versions (e.g. 1.1.3.devN+g<sha>).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the hand-maintained
[project].versioninpyproject.tomlwithhatch-vcsso the package version is derived solely from git tags (v*).Releases are now cut by tagging
vX.Y.Z; untagged commits produce PEP 440 dev versions (e.g.1.1.3.devN+g<sha>).Changes
pyproject.tomlrequires = ["hatchling", "hatch-vcs"]dynamic = ["version"](replacesversion = "1.1.2")[tool.hatch.version] source = "vcs"[tool.hatch.build.hooks.vcs] version-file = "src/haclient/_version.py"_version.pyfrom ruff & mypy.src/haclient/__init__.py— preferfrom haclient._version import __version__(build-time); fall back toimportlib.metadata, then0.0.0+unknown..gitignore— ignore generatedsrc/haclient/_version.py.python-ci,python-tests,python-lint,python-typecheck,python-release) —fetch-depth: 0so hatch-vcs can read tags.tests/test_packaging.py— replace static-equality assertion with invariants for dynamic versioning.How releases work now
git tag v1.1.3 && git push --tags_version.pycarry exactly1.1.3.mainbetween tags →1.1.3.devN+g<sha>.Verification
ruff check,ruff format --check,mypy src— clean.pytest --cov-fail-under=95— 329 passed, coverage 97.19%.python -m buildproducedhaclient-1.1.3.dev48+g40a987fca.d20260527.{tar.gz,whl}(derived fromv1.1.2 + 48 commits + dirty).