GRM-34: fix: handle same-version update in release.py

This commit is contained in:
2026-06-21 15:32:07 +00:00
parent 09699696c0
commit f0afa8171a
2 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -103,6 +103,8 @@ def update_init_version(new_version: str) -> None:
"""Update __version__ in __init__.py."""
with open(INIT_FILE) as f:
content = f.read()
if not re.search(r'^__version__\s*=\s*"[^"]*"', content, flags=re.MULTILINE):
raise click.ClickException(_("Could not find __version__ in {file}", file=INIT_FILE))
updated = re.sub(
r'^__version__\s*=\s*"[^"]*"',
f'__version__ = "{new_version}"',
@@ -110,8 +112,6 @@ def update_init_version(new_version: str) -> None:
count=1,
flags=re.MULTILINE,
)
if updated == content:
raise click.ClickException(_("Could not find __version__ in {file}", file=INIT_FILE))
with open(INIT_FILE, "w") as f:
f.write(updated)
+8
View File
@@ -118,6 +118,14 @@ class TestUpdateInitVersion:
update_init_version("0.2.0")
assert '__version__ = "0.2.0"' in init_file.read_text()
def test_same_version_ok(self, tmp_path, monkeypatch) -> None:
"""Updating to the same version should not raise."""
init_file = tmp_path / "__init__.py"
init_file.write_text('__version__ = "0.1.0"\n')
monkeypatch.setattr("scripts.release.INIT_FILE", str(init_file))
update_init_version("0.1.0")
assert '__version__ = "0.1.0"' in init_file.read_text()
def test_no_version_raises(self, tmp_path, monkeypatch) -> None:
init_file = tmp_path / "__init__.py"
init_file.write_text('"""module"""\n')