Skip to content

Fix PyPI publishing: derive version from git tag + emit Metadata-Version 2.4 - #37

Merged
angelnu merged 1 commit into
mainfrom
fix/pypi-publish-metadata
Nov 22, 2026
Merged

angelnu merged 1 commit into
mainfrom
fix/pypi-publish-metadata

Conversation

@angelnu

@angelnu angelnu commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Problem

The v1.3.2 release run of .github/workflows/publish-to-pypi.yml failed:

Checking dist/ttn_client-1.3.0-py3-none-any.whl:
ERROR InvalidDistribution: Invalid distribution metadata: '2.5' is not a valid metadata version

There are two independent root causes behind that single error, and both are fixed here.

1. Version desync (wheel was 1.3.0 while the tag was v1.3.2)

pyproject.toml carried a hard-coded version = "1.3.0", so every release published the same
ttn_client-1.3.0 artifact regardless of the tag — the version never tracked the release.

2. Metadata-Version: 2.5 vs. the twine bundled in the publish action

hatchling was unpinned in [build-system].requires, so CI installed the latest version
(1.33.0 at the time of writing), which emits core metadata 2.5 by default. The
pypa/gh-action-pypi-publish@v1.13.0 used by the workflow ships twine 6.1.0 + packaging 25.0,
which rejects 2.5 — hence the InvalidDistribution error. (2.5 only became accepted by twine in
twine 7, which is what pypa/gh-action-pypi-publish v1.14.x bundles.)

Changes

pyproject.toml

  • The version is now dynamic and derived from the git tag via hatch-vcs:
    dynamic = ["version"], [build-system].requires = ["hatchling", "hatch-vcs"],
    [tool.hatch.version] source = "vcs". A release of tag vX.Y.Z therefore builds a vX.Y.Z
    distribution — the version can no longer desync. fallback-version = "0.0.0" keeps builds
    working in environments without git metadata instead of hard-failing.
  • The emitted core metadata version is pinned to 2.4 for both the wheel and the sdist
    ([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) and
    is deterministic — unlike pinning hatchling itself, whose metadata default is not monotonic
    (1.30 → 2.5, 1.31 → 2.4, 1.32 → 2.5).

.github/workflows/publish-to-pypi.yml

  • actions/checkout now uses fetch-depth: 0, so the release tag is always visible to
    hatch-vcs and the built version is exactly the tag.
  • pypa/gh-action-pypi-publish bumped v1.13.0 → v1.14.3 (drop-in: the action's inputs are
    unchanged between the two versions). Its twine 7 accepts metadata 2.5 as well, so the
    publishing 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, build with build isolation (i.e. CI's latest hatchling==1.33.0).

Baseline — reproduces the failure before the fix

$ git checkout 07bebb4        # main = tag v1.3.2
$ python -m build
* Installed build dependency versions:
  - hatchling==1.33.0
Successfully built ttn_client-1.3.0.tar.gz and ttn_client-1.3.0-py3-none-any.whl

$ python -c "..."             # read METADATA from the wheel
['Metadata-Version: 2.5', 'Version: 1.3.0']      <-- 2.5 + wrong version

$ python -m twine check dist/*          # twine 6.1.0 + packaging 25.0 (= action v1.13.0 bundle)
Checking dist/ttn_client-1.3.0-py3-none-any.whl: ERROR InvalidDistribution:
  Invalid distribution metadata: '2.5' is not a valid metadata version
exit=1

Note that this reproduces the CI error verbatim, with the same twine/packaging
combination the action bundles.

After the fix

Version derived from the tag (local tag on the branch tip, simulating release: published):

$ git tag v1.3.3 && python -m build
* Installed build dependency versions:
  - hatchling==1.33.0
  - hatch-vcs==0.5.0
Successfully built ttn_client-1.3.3.tar.gz and ttn_client-1.3.3-py3-none-any.whl

WHEEL: dist/ttn_client-1.3.3-py3-none-any.whl
  Metadata-Version: 2.4
  Name: ttn_client
  Version: 1.3.3
  Requires-Python: >=3.11
  Requires-Dist: aiohttp
SDIST: dist/ttn_client-1.3.3.tar.gz
  Metadata-Version: 2.4
  Name: ttn_client
  Version: 1.3.3

twine check with both twine versions — the one bundled by the old action and the one bundled
by the new action:

$ python -m twine check dist/*          # twine 6.1.0 + packaging 25.0 (= action v1.13.0 bundle)
Checking dist/ttn_client-1.3.3-py3-none-any.whl: PASSED
Checking dist/ttn_client-1.3.3.tar.gz: PASSED
exit=0

$ python -m twine check dist/*          # twine 7.0.0 + packaging 26.2 (= action v1.14.3 bundle)
Checking dist/ttn_client-1.3.3-py3-none-any.whl: PASSED
Checking dist/ttn_client-1.3.3.tar.gz: PASSED
exit=0

Also checked that the fix does not break the other paths:

# untagged branch tip -> dev version (never a bogus release version)
Successfully built ttn_client-1.3.3.dev1+g11a3e0bdf-py3-none-any.whl

# wheel built from the extracted sdist (no .git) keeps the right version
Successfully built ttn_client-1.3.3-py3-none-any.whl

# wheel installs and reports the right metadata
$ pip install dist/ttn_client-1.3.3-py3-none-any.whl
Name: ttn-client   Version: 1.3.3
$ python -c "import importlib.metadata as m; print(m.version('ttn_client'))"
1.3.3

# editable install (used by scripts/setup / requirements_dev.txt) still works
$ pip install -e .  ->  ttn-client==1.3.3.dev1+g11a3e0bdf

# test suite against the built wheel
$ pytest -q
19 passed in 0.22s

# shallow, tag-less clone (like actions/checkout with fetch-depth: 2, fetch-tags: false):
# builds fine (no hard failure), so the Test workflow is unaffected
Successfully built ttn_client-0.0.1.dev2+g693653d0f-py3-none-any.whl

Follow-up for the maintainer (not part of this PR)

  • The already-failed v1.3.2 release 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 the
    workflow on a tag that contains this change.
  • Unrelated observation from the push output: GitHub reports a dependabot alert on the default
    branch (1 critical vulnerability). Not touched by this PR — raised here only for visibility.

…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.
@angelnu
angelnu merged commit d60194b into main Nov 22, 2026
4 checks passed
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