Skip to content

Commit

Permalink
Add python-module-def check to SpecCheck
Browse files Browse the repository at this point in the history
This patch adds a new warning when detecting the use of python_module
macro definition in the spec file.

It's included by default in python-rpm-macros so every modern distro
should have this module defined.

This macro was added by py2pack by default in new packages, but now it's
removed:
openSUSE/py2pack#166
  • Loading branch information
danigm committed Oct 25, 2022
1 parent 08df0b0 commit 4e88e42
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rpmlint/checks/SpecCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def re_tag_compile(tag):
tarball_regex = re.compile(r'\.(?:t(?:ar|[glx]z|bz2?)|zip)\b', re.IGNORECASE)

python_setup_test_regex = re.compile(r'^[^#]*(setup.py test)')
python_module_def_regex = re.compile(r'^[^#]*%{\?!python_module:%define python_module()')

UNICODE_NBSP = '\xa0'

Expand Down Expand Up @@ -364,6 +365,7 @@ def _check_line(self, line):
self._checkline_valid_groups(line)
self._checkline_macros_in_comments(line)
self._checkline_python_setup_test(line)
self._checkline_python_module_def(line)

# If statement, starts
if ifarch_regex.search(line):
Expand Down Expand Up @@ -740,3 +742,12 @@ def _checkline_python_setup_test(self, line):
# Test if the "python setup.py test" deprecated subcommand is used
if self.current_section == 'check' and python_setup_test_regex.search(line):
self.output.add_info('W', self.pkg, 'python-setup-test', line[:-1])

def _checkline_python_module_def(self, line):
"""
Test if the "python_module" macro is defined in the spec file
This macro was in py2pack but now it should be provided by
python-rpm-macros
"""
if python_module_def_regex.search(line):
self.output.add_info('W', self.pkg, 'python-module-def', line[:-1])
6 changes: 6 additions & 0 deletions rpmlint/descriptions/SpecCheck.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,9 @@ python-setup-test="""
The python setup.py test subcommand is deprecated and should be replaced with a
modern testing tool like %pytest or %pyunittest discover -v.
"""
python-module-def="""
The spec file contains a conditional definition of python_module macro, this
macro is present in recent versions of python-rpm-macros.
The following conditional python_module macro definition can be removed:
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
"""
36 changes: 36 additions & 0 deletions test/spec/python-module-def.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}

Name: python-module-def
Version: 1.0
Release: 0
Summary: python-module-def warning
License: MIT
URL: https://www.example.com
Source: Source.tar.gz
BuildRequires: gcc
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%description
A test specfile with python setup.py test that is deprecated.

%prep
%setup -q

%build
%configure
%make_build

%install
%make_install

%check
%pytest

%post
%postun

%files
%license COPYING
%doc ChangeLog README

%changelog
27 changes: 27 additions & 0 deletions test/test_speccheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,30 @@ def test_python_setup_test(package, speccheck):
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-setup-test' in out


@pytest.mark.parametrize('package', ['spec/python-module-def'])
def test_python_module_definition(package, speccheck):
"""Test if python_module macro is defined in the spec file."""
output, test = speccheck
pkg = get_tested_spec_package(package)
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-module-def' in out


@pytest.mark.parametrize('package', [
'spec/SpecCheck',
'spec/SpecCheck2',
'spec/SpecCheck3',
'spec/SpecCheck4',
])
def test_python_module_definition_not_present(package, speccheck):
"""Test if python_module macro warning is not shown if the macro is not
defined in the spec file.
"""
output, test = speccheck
pkg = get_tested_spec_package(package)
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-module-def' not in out

0 comments on commit 4e88e42

Please sign in to comment.