From 69df9b6b95c48369ad6088bb4444a3dc22898bcc Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Tue, 7 Apr 2026 19:38:15 +0300 Subject: [PATCH] fix(ci): normalize non-PEP440 versions before stamping pyproject.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a tag or CI ref is not PEP 440 compliant (e.g. 'dev', 'nightly', 'snapshot-2024'), the previous detect_version stamped it raw into pyproject.toml, which then broke 'pip install' with: configuration error: project.version must be pep440 Add a regex check after stripping the leading 'v'. If the result is not PEP 440, substitute '0.0.0.dev0' and warn. Pattern from ClaudeCodeFacts/gitea-python-ci-cd.md ยง3. --- build-common.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build-common.sh b/build-common.sh index 30e7765..c1b0d98 100644 --- a/build-common.sh +++ b/build-common.sh @@ -23,6 +23,17 @@ detect_version() { VERSION_CLEAN="${VERSION#v}" + # Normalize non-PEP440 labels (e.g. "dev", "nightly", "snapshot") to a + # valid PEP440 dev release. Without this, pip/setuptools rejects + # pyproject.toml with: `project.version` must be pep440. + # + # Valid forms: 1.2.3, 1.2.3a1, 1.2.3rc2, 1.2.3.dev0, 1.2.3.post1, +local + # Invalid forms: dev, vdev, nightly, snapshot-2024 + if ! [[ "$VERSION_CLEAN" =~ ^[0-9]+(\.[0-9]+)*((a|b|rc|\.dev|\.post)[0-9]+)*(\+[a-zA-Z0-9.]+)?$ ]]; then + echo " Warning: '$VERSION_CLEAN' is not PEP440-compliant, using 0.0.0.dev0" + VERSION_CLEAN="0.0.0.dev0" + fi + # Stamp version into pyproject.toml (single source of truth) sed -i "s/^version = .*/version = \"${VERSION_CLEAN}\"/" pyproject.toml }