-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathvalidate_requirements_reference.py
More file actions
53 lines (42 loc) · 1.76 KB
/
validate_requirements_reference.py
File metadata and controls
53 lines (42 loc) · 1.76 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
48
49
50
51
52
53
#!/usr/bin/env python3
"""
Validate that requirements-reference.txt exists and pyprecice version
matches PYTHON_BINDINGS_REF in reference_versions.yaml.
Exit 0 on success, 1 on failure.
"""
import re
import sys
from pathlib import Path
TOOLS_TESTS = Path(__file__).parent
REFERENCE_VERSIONS = TOOLS_TESTS / "reference_versions.yaml"
REQUIREMENTS_REF = TOOLS_TESTS / "requirements-reference.txt"
def main() -> int:
if not REQUIREMENTS_REF.exists():
print(f"ERROR: {REQUIREMENTS_REF} not found. Run update_requirements_reference.py.", file=sys.stderr)
return 1
# Load PYTHON_BINDINGS_REF
ref_text = REFERENCE_VERSIONS.read_text()
ref_match = re.search(r'PYTHON_BINDINGS_REF:\s*["\']([^"\']+)["\']', ref_text)
if not ref_match:
print("ERROR: PYTHON_BINDINGS_REF not found in reference_versions.yaml", file=sys.stderr)
return 1
expected_ver = ref_match.group(1).lstrip("v").strip()
# Parse pyprecice from requirements-reference.txt
req_text = REQUIREMENTS_REF.read_text()
precice_match = re.search(r"pyprecice\s*==\s*([\w.]+)", req_text)
if not precice_match:
print("ERROR: pyprecice not found in requirements-reference.txt", file=sys.stderr)
return 1
actual_ver = precice_match.group(1).strip()
if actual_ver != expected_ver:
print(
f"ERROR: pyprecice version mismatch: requirements-reference.txt has {actual_ver}, "
f"reference_versions.yaml PYTHON_BINDINGS_REF has {ref_match.group(1)}. "
"Run: python3 update_requirements_reference.py",
file=sys.stderr,
)
return 1
print(f"OK: requirements-reference.txt pyprecice=={actual_ver} matches reference_versions.yaml")
return 0
if __name__ == "__main__":
sys.exit(main())