Skip to content

Commit fd0d6da

Browse files
committed
fix release date & add version consistency test
1 parent 09d95d2 commit fd0d6da

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<span id="v1-9-2" />
1919

20-
## ...`v1.9.2`
20+
## 16.12.2025`v1.9.2`
2121
* Added a new class `LazyRegex` to the `regex` module, which is used to define regex patterns that are only compiled when they are used for the first time.
2222
* Removed unnecessary character escaping in the precompiled regex patterns in the `console` module.
2323
* Removed all the runtime type-checks that can also be checked using static type-checking tools, since you're supposed to use type checkers in modern python anyway, and to improve performance.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,5 @@ testpaths = [
166166
"tests/test_regex.py",
167167
"tests/test_string.py",
168168
"tests/test_system.py",
169+
"tests/test_version_consistency.py",
169170
]

tests/test_version_consistency.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from typing import Optional
2+
from pathlib import Path
3+
import subprocess
4+
import pytest
5+
import re
6+
7+
# DEFINE PATHS RELATIVE TO THIS TEST FILE tests/test_version.py
8+
ROOT_DIR = Path(__file__).parent.parent
9+
PYPROJECT_PATH = ROOT_DIR / "pyproject.toml"
10+
INIT_PATH = ROOT_DIR / "src" / "xulbux" / "__init__.py"
11+
12+
13+
def get_current_branch() -> Optional[str]:
14+
try:
15+
result = subprocess.run(["git", "branch", "--show-current"], capture_output=True, text=True, check=True)
16+
return result.stdout.strip()
17+
except (subprocess.CalledProcessError, FileNotFoundError):
18+
return None
19+
20+
21+
def get_file_version(file_path: Path, pattern: str) -> Optional[str]:
22+
if not file_path.exists():
23+
return None
24+
25+
with open(file_path, "r", encoding="utf-8") as f:
26+
content = f.read()
27+
match = re.search(pattern, content, re.MULTILINE)
28+
if match:
29+
return match.group(1)
30+
31+
return None
32+
33+
34+
################################################## VERSION CONSISTENCY TEST ##################################################
35+
36+
37+
def test_version_consistency():
38+
"""Verifies that the version numbers in `pyproject.toml` and `__init__.py`
39+
match the version specified in the current release branch name (`dev/1.X.Y`)."""
40+
# SKIP IF WE CAN'T DETERMINE THE BRANCH (DETACHED HEAD OR NOT A GIT REPO)
41+
if not (branch_name := get_current_branch()):
42+
pytest.skip("Could not determine git branch name")
43+
44+
# SKIP IF BRANCH NAME DOESN'T MATCH RELEASE PATTERN dev/1.X.Y
45+
if not (branch_match := re.match(r"^dev/(1\.[0-9]+\.[0-9]+)$", branch_name)):
46+
pytest.skip(f"Current branch '{branch_name}' is not a release branch (dev/1.X.Y)")
47+
48+
expected_version = branch_match.group(1)
49+
50+
# EXTRACT VERSIONS
51+
pyproject_version = get_file_version(PYPROJECT_PATH, r'^version\s*=\s*"([^"]+)"')
52+
init_version = get_file_version(INIT_PATH, r'^__version__\s*=\s*"([^"]+)"')
53+
54+
assert pyproject_version is not None, f"Could not find var 'version' in {PYPROJECT_PATH}"
55+
assert init_version is not None, f"Could not find var '__version__' in {INIT_PATH}"
56+
57+
assert pyproject_version == expected_version, \
58+
f"Hardcoded lib-version in pyproject.toml ({pyproject_version}) does not match branch version ({expected_version})"
59+
60+
assert init_version == expected_version, \
61+
f"Hardcoded lib-version in src/xulbux/__init__.py ({init_version}) does not match branch version ({expected_version})"

0 commit comments

Comments
 (0)