-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_sync.py
More file actions
executable file
·47 lines (35 loc) · 1.51 KB
/
Copy pathversion_sync.py
File metadata and controls
executable file
·47 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Created on Jun 07 19:54:24 2026"""
# Pre-commit hook: verify that README.md mentions the same version as version.py.
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[0]
VERSION_FILE = ROOT / "src" / "plotez" / "version.py"
README_FILE = ROOT / "README.md"
def get_version_from_version_py() -> str:
"""Extract __version__ value from version.py."""
content = VERSION_FILE.read_text(encoding="utf-8")
match = re.search(r'^__version__\s*=\s*["\']([^"\']+)["\']', content, re.MULTILINE)
if not match:
print(f"ERROR: Could not find __version__ in {VERSION_FILE}", file=sys.stderr)
sys.exit(1)
return match.group(1)
def check_readme_contains_version(version: str) -> bool:
"""Return True if README.md contains the version string (with or without the 'v' prefix)."""
content = README_FILE.read_text(encoding="utf-8")
# Accept both a bare version and v-prefixed version (e.g., 0.3.3 and v0.3.3)
return version in content
def main() -> None:
version = get_version_from_version_py()
if not check_readme_contains_version(version):
print(
f"ERROR: Version mismatch!\n"
f" version.py says : {version}\n"
f" README.md does NOT contain '{version}' (or 'v{version}').\n"
f" Please update README.md before committing.",
file=sys.stderr,
)
sys.exit(1)
print(f"OK: README.md is in sync with version.py (version {version}).")
if __name__ == "__main__":
main()