From 57df09ba87d395f3763d04bc9ecaf3e3bc3d1870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Wed, 11 Feb 2026 16:32:19 +0100 Subject: [PATCH] Ignore, but process, conditional macro expansions when updating Release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flattening the nodes of parsed release string removes conditional macro expansions, so it's not possible to reconstruct them. Process them instead, but treat them as simple string literals, we don't need to process their bodies anyway. Signed-off-by: Nikola Forró --- agents/tests/unit/test_tools.py | 16 ++++++++++++++++ agents/tools/specfile.py | 8 ++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/agents/tests/unit/test_tools.py b/agents/tests/unit/test_tools.py index 0f94408f..bc69c961 100644 --- a/agents/tests/unit/test_tools.py +++ b/agents/tests/unit/test_tools.py @@ -267,6 +267,22 @@ async def run_and_check(spec, expected_release, error=False): await run_and_check(minimal_spec, "1%{?dist}" if rebase else "3%{?dist}") await run_and_check(autorelease_spec, "%autorelease") + with specfile.Specfile(minimal_spec) as spec: + spec.raw_release = "5%{?alphatag:.%{alphatag}}%{?dist}.8" + + if not dist_git_branch.startswith("rhel-"): + await run_and_check( + minimal_spec, + ( + "1%{?alphatag:.%{alphatag}}%{?dist}" + if rebase + else "6%{?alphatag:.%{alphatag}}%{?dist}" + ), + ) + else: + await run_and_check(minimal_spec, "0%{?dist}.1" if rebase else "5%{?alphatag:.%{alphatag}}%{?dist}.9") + await run_and_check(minimal_spec, "0%{?dist}.1" if rebase else "5%{?alphatag:.%{alphatag}}%{?dist}.10") + @pytest.mark.asyncio async def test_get_cwd(tmp_path): diff --git a/agents/tools/specfile.py b/agents/tools/specfile.py index 09ecb75b..6097a538 100644 --- a/agents/tools/specfile.py +++ b/agents/tools/specfile.py @@ -164,10 +164,6 @@ async def _get_latest_higher_stream_build(package: str, candidate_tag: str) -> E [build] = builds return EVR(epoch=build["epoch"] or 0, version=build["version"], release=build["release"]) - @staticmethod - def _parse_release(release: str) -> list[Node]: - return list(ValueParser.flatten(ValueParser.parse(release))) - @staticmethod def _find_macro(name: str, nodes: list[Node]) -> int | None: for index, node in reversed(list(enumerate(nodes))): @@ -182,7 +178,7 @@ def _find_macro(name: str, nodes: list[Node]) -> int | None: async def _bump_or_reset_release(cls, spec_path: Path, rebase: bool) -> None: with Specfile(spec_path) as spec: current_release = spec.raw_release - nodes = cls._parse_release(current_release) + nodes = ValueParser.parse(current_release) autorelease_index = cls._find_macro("autorelease", nodes) dist_index = cls._find_macro("dist", nodes) @@ -220,7 +216,7 @@ async def _set_zstream_release( higher_stream_base_release, _ = latest_higher_stream_build.release.rsplit(".el", maxsplit=1) with Specfile(spec_path) as spec: current_release = spec.raw_release - nodes = cls._parse_release(current_release) + nodes = ValueParser.parse(current_release) autorelease_index = cls._find_macro("autorelease", nodes) dist_index = cls._find_macro("dist", nodes)