diff --git a/specfile/specfile.py b/specfile/specfile.py index 385986a..d5120ec 100644 --- a/specfile/specfile.py +++ b/specfile/specfile.py @@ -12,7 +12,11 @@ from specfile.changelog import Changelog, ChangelogEntry, guess_packager from specfile.context_management import ContextManager -from specfile.exceptions import SourceNumberException, SpecfileException +from specfile.exceptions import ( + SourceNumberException, + SpecfileException, + UnterminatedMacroException, +) from specfile.formatter import formatted from specfile.macro_definitions import ( CommentOutStyle, @@ -433,12 +437,16 @@ def contains_autochangelog(section: Section) -> bool: if line.lstrip().startswith("#"): # skip comments continue - for node in ValueParser.flatten(ValueParser.parse(line)): - if ( - isinstance(node, (MacroSubstitution, EnclosedMacroSubstitution)) - and node.name == "autochangelog" - ): - return True + try: + for node in ValueParser.flatten(ValueParser.parse(line)): + if ( + isinstance(node, (MacroSubstitution, EnclosedMacroSubstitution)) + and node.name == "autochangelog" + ): + return True + except UnterminatedMacroException: + # ignore unparseable lines + continue return False @property diff --git a/tests/integration/test_specfile.py b/tests/integration/test_specfile.py index b047c28..bc6f2c1 100644 --- a/tests/integration/test_specfile.py +++ b/tests/integration/test_specfile.py @@ -329,7 +329,9 @@ def test_autorelease(spec_rpmautospec, raw_release, has_autorelease): @pytest.mark.skipif( rpm.__version__ < "4.16", reason="%autochangelog requires rpm 4.16 or higher" ) -def test_autochangelog(spec_rpmautospec, spec_conditionalized_changelog): +def test_autochangelog( + spec_rpmautospec, spec_conditionalized_changelog, spec_autosetup +): spec = Specfile(spec_rpmautospec) assert spec.has_autochangelog with spec.changelog() as changelog: @@ -350,6 +352,10 @@ def test_autochangelog(spec_rpmautospec, spec_conditionalized_changelog): assert changelogs[0] == changelog with spec.changelog(changelogs[1]) as changelog: assert changelog[-1].content == ["test"] + spec = Specfile(spec_autosetup) + with spec.changelog() as changelog: + changelog[0].content += "%" + assert not spec.has_autochangelog @pytest.mark.skipif(