Skip to content

Commit

Permalink
PythonCheck: Handle extras in req check
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm authored and Conan-Kudo committed Jun 22, 2023
1 parent 1c03c47 commit c40ff52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rpmlint/checks/PythonCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def _check_require(self, pkg, requirement):
python3-foo, etc.
"""

names = self._module_names(requirement.name)
names = self._module_names(requirement.name, extras=requirement.extras)

# Add pythonX-foo variants
names += [f'python\\d*-{re.escape(i)}' for i in names]
regex = '|'.join(names)
Expand Down Expand Up @@ -201,7 +202,8 @@ def _check_leftover_requirements(self, pkg, requirements):
pythonpac = re.compile(r'^python\d*-(?P<name>.+)$')
reqs = set()
for i in requirements:
reqs.add(i.name.lower())
for n in self._module_names(i.name, extras=i.extras):
reqs.add(n.lower())

for req in pkg.req_names:
match = pythonpac.match(req)
Expand All @@ -219,7 +221,7 @@ def _check_leftover_requirements(self, pkg, requirements):
if not (names & reqs):
self.output.add_info('W', pkg, 'python-leftover-require', req)

def _module_names(self, module_name):
def _module_names(self, module_name, extras=None):
"""
Return a list with possible variants of the module name,
replacing "-", "_".
Expand All @@ -230,6 +232,11 @@ def _module_names(self, module_name):
variants.append(module_name.replace('-', '_'))
variants.append(module_name.replace('_', '-'))

# Look also for python-MOD-EXTRA
if extras:
for e in extras:
variants += self._module_names(f'{module_name}-{e}')

return [
module_name,
*variants,
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions test/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def test_python_tests_in_site_packages(tmp_path, package, pythoncheck):
'binary/python3-icecream-2.1.3',
'binary/python310-jupyter-server-fileid-0.9.0',
'binary/python310-scikit-build-0.17.2',
'binary/python310-jupyter-events-0.6.3',
])
def test_python_dependencies(tmp_path, package, pythoncheck):
output, test = pythoncheck
Expand Down

0 comments on commit c40ff52

Please sign in to comment.