Skip to content

Derive package version from git tags (hatch-vcs) - #53

Merged
amarcozzi merged 1 commit into
mainfrom
chore/hatch-vcs-versioning
Aug 24, 2026
Merged

Derive package version from git tags (hatch-vcs)#53
amarcozzi merged 1 commit into
mainfrom
chore/hatch-vcs-versioning

Conversation

@amarcozzi

Copy link
Copy Markdown
Contributor

Why

The v0.5.2 release workflow failed because pyproject.toml still hardcoded version = "0.5.1". python -m build produced leaflux-0.5.1, which already exists on PyPI, so twine upload 409'd. The version number has to be hand-edited before every release, and it's easy to forget.

What

  • Switch the build backend from setuptools → hatchling, and add hatch-vcs so the version is derived from the git tag at build time (dynamic = ["version"]). Same approach fastfuels-core already uses.
  • Add fetch-depth: 0 to the two release jobs that build (upload-to-test-pypi, upload-to-pypi) so the tag is present for hatch-vcs to read. The two test jobs install from PyPI and don't build, so they're untouched.

Verified locally

  • Clean checkout at a vX.Y.Z tag builds leaflux-X.Y.Z exactly.
  • Dirty/untagged tree builds a .devN+g<sha> version (expected).
  • Wheel contains only the leaflux/ package (6 modules) + dist-info — no docs/, test/, or data/.

⚠️ To actually ship 0.5.2

The existing v0.5.2 tag points at the old (setuptools) commit, so it won't pick this up. After merge, either re-tag v0.5.2 (delete + recreate on the new main) or cut a fresh v0.5.3 release. 0.5.2 was never published, so either is clean.

Replace the hardcoded project.version with hatch-vcs dynamic versioning
so the version comes from the git tag at build time, instead of a number
that has to be hand-edited before each release (the mismatch that broke
the v0.5.2 release: pyproject still said 0.5.1, so the build produced an
already-published artifact and twine 409'd).

Switch the build backend setuptools -> hatchling and add fetch-depth: 0
to the two release jobs that build, so the tag is present for hatch-vcs
to read.
@amarcozzi
amarcozzi merged commit 168877d into main Aug 24, 2026
12 checks passed
@amarcozzi
amarcozzi deleted the chore/hatch-vcs-versioning branch August 24, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant