Skip to content

Commit 4097390

Browse files
committed
Fix PyPI local version error
- Add 'no-local-version' scheme to setuptools_scm config - Update GitHub Actions to only build from tags (not main branch) - Enhance release script to check for main branch - Ensure clean versions for PyPI releases This prevents the 'local versions not allowed' error on PyPI by: 1. Only building from clean, tagged commits 2. Using 'no-local-version' scheme to avoid +hash suffixes 3. Requiring main branch for releases
1 parent 53315f8 commit 4097390

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
pytest tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=src/echr_extractor --cov-report=xml --cov-report=html
6666
6767
build:
68+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
6869
name: Build Python package
6970
runs-on: ubuntu-latest
7071
steps:
@@ -90,7 +91,7 @@ jobs:
9091
path: dist/
9192

9293
pypi-publish:
93-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
94+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
9495
name: Publish to PyPI
9596
needs: build
9697
runs-on: ubuntu-latest
@@ -110,7 +111,7 @@ jobs:
110111
uses: pypa/gh-action-pypi-publish@release/v1
111112

112113
github-release:
113-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
114+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
114115
name: Sign the Python distribution with Sigstore and upload them to GitHub Releases
115116
needs:
116117
- pypi-publish

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ disallow_untyped_defs = true
108108

109109
[tool.setuptools_scm]
110110
write_to = "src/echr_extractor/_version.py"
111+
# Ensure clean versions for PyPI releases
112+
local_scheme = "no-local-version"
113+
# Use distance-based versioning for development
114+
fallback_version = "0.0.0"

scripts/release.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def check_working_directory_clean():
6464
print("Error: Working directory is not clean. Please commit or stash changes.")
6565
print("Uncommitted changes:")
6666
print(result.stdout)
67+
print("\nThis is required to ensure clean version numbers for PyPI releases.")
68+
sys.exit(1)
69+
70+
# Also check that we're on main branch
71+
result = run_command("git branch --show-current")
72+
current_branch = result.stdout.strip()
73+
if current_branch != "main":
74+
print(f"Error: You must be on the 'main' branch to create releases.")
75+
print(f"Current branch: {current_branch}")
76+
print("Please switch to main branch: git checkout main")
6777
sys.exit(1)
6878

6979

0 commit comments

Comments
 (0)