fix(ci): normalize non-PEP440 versions before stamping pyproject.toml
Lint & Test / test (push) Successful in 16s
Lint & Test / test (push) Successful in 16s
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user