Skip to content

Commit 93be189

Browse files
committed
Add scripts/version.py
1 parent cdd1cf4 commit 93be189

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
mode: simulation
161161
- name: Run tests (naïve)
162162
run: find python/evalica -name "*.so" -delete -o -name "*.pyd" -delete && pytest
163-
cff:
163+
meta:
164164
runs-on: ubuntu-slim
165165
steps:
166166
- uses: actions/checkout@v6
@@ -170,3 +170,5 @@ jobs:
170170
enable-cache: false
171171
- name: Validate CITATION.cff
172172
run: uvx cffconvert --validate
173+
- name: Validate versions
174+
run: python3 scripts/version.py

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "evalica"
7+
version = "0.4.0rc1"
78
license = "Apache-2.0"
89
description = "Evalica, your favourite evaluation toolkit."
910
keywords = [
@@ -42,7 +43,6 @@ classifiers = [
4243
"Topic :: Software Development :: Libraries",
4344
"Typing :: Typed",
4445
]
45-
dynamic = ["version"]
4646

4747
[project.optional-dependencies]
4848
dev = [

scripts/version.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
"""Check that version numbers are consistent across its definitions."""
3+
4+
import re
5+
import sys
6+
from pathlib import Path
7+
8+
9+
def normalize_version(version: str) -> str:
10+
"""Normalize version strings to handle different pre-release conventions."""
11+
version = version.strip().strip('"').strip("'")
12+
version = re.sub(r"\+.*$", "", version)
13+
version = re.sub(r"-rc\.", "rc", version)
14+
version = re.sub(r"\.rc\.", "rc", version)
15+
version = re.sub(r"-pre\.", "rc", version)
16+
version = re.sub(r"\.pre\.", "rc", version)
17+
version = re.sub(r"-rc", "rc", version)
18+
version = re.sub(r"-pre", "rc", version)
19+
return version
20+
21+
22+
def extract_version(path: Path, pattern: str) -> str:
23+
"""Extract version from file."""
24+
content = path.read_text()
25+
match = re.search(pattern, content, re.MULTILINE)
26+
if not match:
27+
raise ValueError(f"Could not find version in {path}")
28+
return match.group(1)
29+
30+
31+
def main() -> int:
32+
"""Main entry point."""
33+
root = Path(__file__).parent.parent
34+
35+
files = {
36+
"Cargo.toml": (root / "Cargo.toml", r'^version\s*=\s*["\']([^"\']+)["\']'),
37+
"pyproject.toml": (root / "pyproject.toml", r'^version\s*=\s*["\']([^"\']+)["\']'),
38+
"__init__.py": (root / "python" / "evalica" / "__init__.py", r'__version__\s*=\s*["\']([^"\']+)["\']'),
39+
}
40+
41+
versions = {}
42+
for name, (path, pattern) in files.items():
43+
if not path.exists():
44+
print(f"Error: {path} not found", file=sys.stderr)
45+
return 1
46+
versions[name] = normalize_version(extract_version(path, pattern))
47+
48+
for name, version in versions.items():
49+
print(f"{name}: {version}")
50+
51+
if len(set(versions.values())) != 1:
52+
return 1
53+
54+
return 0
55+
56+
57+
if __name__ == "__main__":
58+
sys.exit(main())

0 commit comments

Comments
 (0)