Repository navigation
Fix PyPI publishing: derive version from git tag + emit Metadata-Version 2.4 - #37
Merged
Merged
Conversation
…rsion 2.4
The v1.3.2 release failed to publish with:
ERROR InvalidDistribution: Invalid distribution metadata:
'2.5' is not a valid metadata version
Two root causes, both fixed here.
1. Version desync. pyproject.toml carried a static version = "1.3.0",
so the wheel was built as ttn_client-1.3.0 no matter which tag was
released. The version is now dynamic and derived from the git tag via
hatch-vcs, so a release of tag vX.Y.Z builds a vX.Y.Z distribution
and can never desync again. fallback-version keeps builds working
when no git metadata is available; the publish workflow now checks
out with fetch-depth: 0 so the release tag is always visible.
2. Metadata-Version 2.5 vs the publish action's twine. hatchling >= 1.30
emits core metadata 2.5 by default, which the twine 6.1 /
packaging 25.0 bundled in pypa/gh-action-pypi-publish v1.13.0 rejects.
The emitted metadata version is now pinned to 2.4 for both the wheel
and the sdist (hatchling's core-metadata-version option, supported
since 1.21), and the action is bumped to v1.14.3, whose twine 7
accepts 2.5 as well.
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.
Problem
The
v1.3.2release run of.github/workflows/publish-to-pypi.ymlfailed:There are two independent root causes behind that single error, and both are fixed here.
1. Version desync (wheel was
1.3.0while the tag wasv1.3.2)pyproject.tomlcarried a hard-codedversion = "1.3.0", so every release published the samettn_client-1.3.0artifact regardless of the tag — the version never tracked the release.2.
Metadata-Version: 2.5vs. the twine bundled in the publish actionhatchlingwas unpinned in[build-system].requires, so CI installed the latest version(
1.33.0at the time of writing), which emits core metadata 2.5 by default. Thepypa/gh-action-pypi-publish@v1.13.0used by the workflow shipstwine 6.1.0+packaging 25.0,which rejects 2.5 — hence the
InvalidDistributionerror. (2.5only became accepted by twine intwine 7, which is what
pypa/gh-action-pypi-publishv1.14.x bundles.)Changes
pyproject.tomlhatch-vcs:dynamic = ["version"],[build-system].requires = ["hatchling", "hatch-vcs"],[tool.hatch.version] source = "vcs". A release of tagvX.Y.Ztherefore builds avX.Y.Zdistribution — the version can no longer desync.
fallback-version = "0.0.0"keeps buildsworking in environments without git metadata instead of hard-failing.
(
[tool.hatch.build.targets.wheel]/[tool.hatch.build.targets.sdist],core-metadata-version = "2.4"). This is hatchling's supported option (present since 1.21) andis deterministic — unlike pinning
hatchlingitself, whose metadata default is not monotonic(1.30 → 2.5, 1.31 → 2.4, 1.32 → 2.5).
.github/workflows/publish-to-pypi.ymlactions/checkoutnow usesfetch-depth: 0, so the release tag is always visible tohatch-vcsand the built version is exactly the tag.pypa/gh-action-pypi-publishbumpedv1.13.0→v1.14.3(drop-in: the action's inputs areunchanged between the two versions). Its
twine 7accepts metadata 2.5 as well, so thepublishing pipeline is no longer sensitive to the metadata version at all.
No other files are touched. The repo keeps no CHANGELOG, and the README does not state a version,
so neither needed updating.
How this was verified
Local Python 3.12,
buildwith build isolation (i.e. CI's latesthatchling==1.33.0).Baseline — reproduces the failure before the fix
Note that this reproduces the CI error verbatim, with the same
twine/packagingcombination the action bundles.
After the fix
Version derived from the tag (local tag on the branch tip, simulating
release: published):twine checkwith both twine versions — the one bundled by the old action and the one bundledby the new action:
Also checked that the fix does not break the other paths:
Follow-up for the maintainer (not part of this PR)
v1.3.2release cannot be republished by simply re-running the failed job:GitHub re-runs use the workflow file from the original commit, which still has the bug. To
publish the fix, merge this PR and publish the next release (e.g.
v1.3.3), or re-run theworkflow on a tag that contains this change.
branch (1 critical vulnerability). Not touched by this PR — raised here only for visibility.