From bd5bc904d696558cc63cbec1e5b9dc00e80190a5 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Wed, 20 Mar 2024 08:22:36 +0100 Subject: [PATCH] Do not embrace macros inside %python_module Fix https://github.com/rpm-software-management/spec-cleaner/issues/321 --- spec_cleaner/rpmregexp.py | 1 + spec_cleaner/rpmsection.py | 7 ++++++- tests/in/python-conditional-buildrequires.spec | 15 +++++++++++++++ tests/out/python-conditional-buildrequires.spec | 14 ++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/in/python-conditional-buildrequires.spec create mode 100644 tests/out/python-conditional-buildrequires.spec diff --git a/spec_cleaner/rpmregexp.py b/spec_cleaner/rpmregexp.py index 97b59b1..466c199 100644 --- a/spec_cleaner/rpmregexp.py +++ b/spec_cleaner/rpmregexp.py @@ -138,6 +138,7 @@ class Regexp(object): r'%{?(python_sitelib|python_sitearch|python_bin_suffix|python_version)}?' ) re_python_interp_expand = re.compile(r'\s+(python)\s+') + re_python_module = re.compile(r'.*\s%{python_module\s.*}') # rpmcopyright re_copyright_string = re.compile(r'^#\s*Copyright\ \(c\)\s*(.*)', re.IGNORECASE) diff --git a/spec_cleaner/rpmsection.py b/spec_cleaner/rpmsection.py index e829a1b..3a54601 100644 --- a/spec_cleaner/rpmsection.py +++ b/spec_cleaner/rpmsection.py @@ -56,7 +56,12 @@ def _complete_cleanup(self, line: str) -> str: line = line.replace(u'\xa0', ' ') if not line.startswith('#'): - if not self.minimal and not self.no_curlification: + is_python_module = self.reg.re_python_module.match(line) + if (not self.minimal + and not self.no_curlification + # Do not embrace macros inside python_module + # gh#rpm-software-management/spec-cleaner#321 + and not is_python_module): line = self.embrace_macros(line) line = self.replace_buildroot(line) line = self.replace_optflags(line) diff --git a/tests/in/python-conditional-buildrequires.spec b/tests/in/python-conditional-buildrequires.spec new file mode 100644 index 0000000..d875ac8 --- /dev/null +++ b/tests/in/python-conditional-buildrequires.spec @@ -0,0 +1,15 @@ +BuildRequires: %{python_module tomli >= 1.2.2 if %python-base < 3.11} +Requires: %oldpython-base + +%install +%python_expand %fdupes %{buildroot}%{python_sitelib} +%python_expand %fdupes %{buildroot}%{python_sitearch} + + +%check +%python_expand PYTHONPATH=%{python_sitearch} nosetests-%{python_bin_suffix} +%python_expand testr-%{python_version} +%{python_expand python -m unittest discover} + +%changelog + diff --git a/tests/out/python-conditional-buildrequires.spec b/tests/out/python-conditional-buildrequires.spec new file mode 100644 index 0000000..a254146 --- /dev/null +++ b/tests/out/python-conditional-buildrequires.spec @@ -0,0 +1,14 @@ +BuildRequires: %{python_module tomli >= 1.2.2 if %python-base < 3.11} +Requires: %{oldpython}-base + +%install +%python_expand %fdupes %{buildroot}%{$python_sitelib} +%python_expand %fdupes %{buildroot}%{$python_sitearch} + + +%check +%python_expand PYTHONPATH=%{$python_sitearch} nosetests-%{$python_bin_suffix} +%python_expand testr-%{$python_version} +%{python_expand $python -m unittest discover} + +%changelog