Skip to content

Commit 21815a1

Browse files
committed
added check for version mismatch
1 parent 98a8e47 commit 21815a1

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ repos:
5252
entry: "bash -c 'set -a && source .env 2>/dev/null; set +a && uv run pytest -rs --cov=amazon_paapi'"
5353
types_or: [python]
5454
pass_filenames: false
55+
56+
- id: version-check
57+
name: Check version consistency
58+
language: system
59+
entry: uv run python scripts/check_version.py
60+
files: (CHANGELOG\.md|pyproject\.toml|docs/conf\.py)$
61+
pass_filenames: false

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ exclude = ["amazon_paapi/sdk/*", "docs/*"]
7272
"PT027", # Use pytest.raises instead of unittest-style
7373
"SLF001", # Private member accessed
7474
]
75+
"scripts/*" = [
76+
"T201", # print found (CLI scripts use print)
77+
]
7578
"api.py" = ["PLR0913"] # Too many arguments to function call
7679

7780
[tool.ruff.format]

scripts/check_version.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
"""Check that version numbers are consistent across the project."""
3+
4+
from __future__ import annotations
5+
6+
import re
7+
import sys
8+
from pathlib import Path
9+
10+
11+
def get_changelog_version() -> str | None:
12+
"""Extract the latest non-Unreleased version from CHANGELOG.md."""
13+
changelog = Path("CHANGELOG.md").read_text()
14+
match = re.search(r"## \[(\d+\.\d+\.\d+)\]", changelog)
15+
return match.group(1) if match else None
16+
17+
18+
def get_pyproject_version() -> str | None:
19+
"""Extract version from pyproject.toml."""
20+
pyproject = Path("pyproject.toml").read_text()
21+
match = re.search(r'^version = "(\d+\.\d+\.\d+)"', pyproject, re.MULTILINE)
22+
return match.group(1) if match else None
23+
24+
25+
def get_docs_version() -> str | None:
26+
"""Extract release version from docs/conf.py."""
27+
conf = Path("docs/conf.py").read_text()
28+
match = re.search(r'^release = "(\d+\.\d+\.\d+)"', conf, re.MULTILINE)
29+
return match.group(1) if match else None
30+
31+
32+
def main() -> int:
33+
"""Check version consistency across project files."""
34+
changelog_version = get_changelog_version()
35+
pyproject_version = get_pyproject_version()
36+
docs_version = get_docs_version()
37+
38+
if not changelog_version:
39+
print("❌ Could not find version in CHANGELOG.md")
40+
return 1
41+
42+
errors = []
43+
44+
if pyproject_version != changelog_version:
45+
errors.append(
46+
f" pyproject.toml: {pyproject_version} (expected {changelog_version})"
47+
)
48+
49+
if docs_version != changelog_version:
50+
errors.append(
51+
f" docs/conf.py: {docs_version} (expected {changelog_version})"
52+
)
53+
54+
if errors:
55+
print(f"❌ Version mismatch! CHANGELOG.md has version {changelog_version}")
56+
print("\nMismatched files:")
57+
for error in errors:
58+
print(error)
59+
print("\nPlease update all version numbers to match.")
60+
return 1
61+
62+
print(f"✅ All versions match: {changelog_version}")
63+
return 0
64+
65+
66+
if __name__ == "__main__":
67+
sys.exit(main())

0 commit comments

Comments
 (0)