From 11a3e0bdf98e3fa069aa2949afd5912894275055 Mon Sep 17 00:00:00 2001 From: software-dev-agent Date: Sun, 22 Nov 2026 18:25:57 +0000 Subject: [PATCH] Fix PyPI publishing: derive version from git tag and emit Metadata-Version 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. --- .github/workflows/publish-to-pypi.yml | 8 +++++++- pyproject.toml | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 7c18650..733357a 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -12,6 +12,10 @@ jobs: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: - uses: actions/checkout@v4.1.2 + with: + # Full history + tags so hatch-vcs derives the version from the + # release tag instead of falling back to a guessed version. + fetch-depth: 0 - name: Set up Python 3.11 uses: actions/setup-python@v5.0.0 with: @@ -24,4 +28,6 @@ jobs: pip install build python -m build - name: Publish release to PyPI - uses: pypa/gh-action-pypi-publish@v1.13.0 + # v1.14.x bundles twine 7, which accepts Metadata-Version 2.5 + # (v1.13.0 bundled twine 6.1 / packaging 25.0, which did not). + uses: pypa/gh-action-pypi-publish@v1.14.3 diff --git a/pyproject.toml b/pyproject.toml index 10d427c..2bbf267 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ttn_client" -version = "1.3.0" +dynamic = ["version"] authors = [ { name="Angel Nunez Mencias", email="pypi@angelnu.com" }, ] @@ -21,5 +21,22 @@ Homepage = "https://github.com/angelnu/thethinksnetwork_python_client" Issues = "https://github.com/angelnu/thethinksnetwork_python_client/issues" [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" + +[tool.hatch.version] +source = "vcs" +# Fallback used when no git tag is reachable (e.g. shallow clones); the +# release workflow fetches the full history so tagged builds always win. +fallback-version = "0.0.0" + +# Keep the emitted core metadata at 2.4: hatchling >= 1.30 defaults to +# Metadata-Version 2.5, which is rejected by the twine bundled in +# pypa/gh-action-pypi-publish < 1.14 (twine < 7). Pinning the emitted +# metadata version is deterministic, unlike pinning hatchling itself +# (its defaults are not monotonic: 1.30 -> 2.5, 1.31 -> 2.4, 1.32 -> 2.5). +[tool.hatch.build.targets.wheel] +core-metadata-version = "2.4" + +[tool.hatch.build.targets.sdist] +core-metadata-version = "2.4"