From 4285bf4a5482c2dc4aa9278fb88dcca2ebd02e97 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 9 Dec 2025 21:02:01 +0100 Subject: [PATCH] Fix: release now skips missing pyproject.toml without failing - Updated update_pyproject_version() to gracefully skip missing or unreadable pyproject.toml - Added corresponding unit test ensuring missing file triggers no exception and no file creation - Updated test wording for spec changelog section - Ref: adjustments discussed in ChatGPT conversation (2025-12-09) - https://chatgpt.com/share/69388024-93e4-800f-a09f-bf78a6b9a53f --- pkgmgr/actions/release/files.py | 19 +++++++++++++---- .../unit/pkgmgr/actions/release/test_files.py | 21 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/pkgmgr/actions/release/files.py b/pkgmgr/actions/release/files.py index a561b31..8393ba7 100644 --- a/pkgmgr/actions/release/files.py +++ b/pkgmgr/actions/release/files.py @@ -85,7 +85,6 @@ def _open_editor_for_changelog(initial_message: Optional[str] = None) -> str: # File update helpers (pyproject + extra packaging + changelog) # --------------------------------------------------------------------------- - def update_pyproject_version( pyproject_path: str, new_version: str, @@ -99,13 +98,25 @@ def update_pyproject_version( version = "X.Y.Z" and replaces the version part with the given new_version string. + + If the file does not exist, it is skipped without failing the release. """ + if not os.path.exists(pyproject_path): + print( + f"[INFO] pyproject.toml not found at: {pyproject_path}, " + "skipping version update." + ) + return + try: with open(pyproject_path, "r", encoding="utf-8") as f: content = f.read() - except FileNotFoundError: - print(f"[ERROR] pyproject.toml not found at: {pyproject_path}") - sys.exit(1) + except OSError as exc: + print( + f"[WARN] Could not read pyproject.toml at {pyproject_path}: {exc}. " + "Skipping version update." + ) + return pattern = r'^(version\s*=\s*")([^"]+)(")' new_content, count = re.subn( diff --git a/tests/unit/pkgmgr/actions/release/test_files.py b/tests/unit/pkgmgr/actions/release/test_files.py index 9ed57af..1c9496e 100644 --- a/tests/unit/pkgmgr/actions/release/test_files.py +++ b/tests/unit/pkgmgr/actions/release/test_files.py @@ -80,6 +80,21 @@ class TestUpdatePyprojectVersion(unittest.TestCase): self.assertNotEqual(cm.exception.code, 0) + def test_update_pyproject_version_missing_file_is_skipped(self) -> None: + """ + If pyproject.toml does not exist, the function must not raise + and must not create the file. It should simply be skipped. + """ + with tempfile.TemporaryDirectory() as tmpdir: + path = os.path.join(tmpdir, "pyproject.toml") + self.assertFalse(os.path.exists(path)) + + # Must not raise an exception + update_pyproject_version(path, "1.2.3", preview=False) + + # Still no file created + self.assertFalse(os.path.exists(path)) + class TestUpdateFlakeVersion(unittest.TestCase): def test_update_flake_version_normal(self) -> None: @@ -352,11 +367,11 @@ class TestUpdateSpecChangelog(unittest.TestCase): with open(path, "r", encoding="utf-8") as f: content = f.read() - # Neue Stanza muss nach %changelog stehen + # New stanza must appear after the %changelog marker self.assertIn("%changelog", content) self.assertIn("Fedora changelog entry", content) self.assertIn("Test Maintainer ", content) - # Alte Einträge müssen erhalten bleiben + # Old entries must still be present self.assertIn("Old Maintainer ", content) def test_update_spec_changelog_preview_does_not_write(self) -> None: @@ -396,7 +411,7 @@ class TestUpdateSpecChangelog(unittest.TestCase): with open(path, "r", encoding="utf-8") as f: content = f.read() - # Im Preview-Modus darf nichts verändert werden + # In preview mode, the spec file must not change self.assertEqual(content, original)