Codebase list dh-python / c130dd4
dh_python3: Don't emit any warnings about unknown packages for modules that we won't depend on. (closes: 1004378) Stefano Rivera 2 years ago
3 changed file(s) with 78 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
0 dh-python (5.20220103) UNRELEASED; urgency=medium
1
2 * dh_python3: Don't emit any warnings about unknown packages for modules
3 that we won't depend on. (closes: 1004378)
4
5 -- Stefano Rivera <stefanor@debian.org> Thu, 27 Jan 2022 09:37:46 -0400
6
07 dh-python (5.20220102) unstable; urgency=medium
18
29 * Allow passing arguments to tox tests.
185185 'or your upstream author to fix requires.txt')
186186 raise Exception('requirement is not valid: %s' % req)
187187 req_d = req_d.groupdict()
188
189 env_marker_alts = ''
190 if req_d['environment_marker']:
191 action = check_environment_marker_restrictions(
192 req,
193 req_d['environment_marker'],
194 impl)
195 if action is False:
196 return
197 elif action is True:
198 pass
199 else:
200 env_marker_alts = ' ' + action
201
188202 name = req_d['name']
189203 details = data.get(name.lower())
190 env_marker_alts = ''
191204 if details:
192205 for item in details:
193206 if version and version not in item.get('versions', version):
194207 # rule doesn't match version, try next one
195208 continue
196
197 env_marker_alts = ''
198 if req_d['environment_marker']:
199 action = check_environment_marker_restrictions(
200 req,
201 req_d['environment_marker'],
202 impl)
203 if action is False:
204 return
205 elif action is True:
206 pass
207 else:
208 env_marker_alts = ' ' + action
209
210209 if not item['dependency']:
211210 return # this requirement should be ignored
212211 if item['dependency'].endswith(')'):
491490 else:
492491 result_key = 'depends'
493492
494 dependency = guess_deps(req=line)
495 if env_action is False:
496 dependency = None
497 elif dependency and isinstance(env_action, str):
493 dependency = None
494 if env_action:
495 dependency = guess_deps(req=line)
496 if dependency and isinstance(env_action, str):
498497 dependency = ', '.join(
499498 part.strip() + ' ' + env_action
500499 for part in dependency.split(','))
532531 requires = metadata.get_all('Requires-Dist', [])
533532 for req in requires:
534533 m = EXTRA_RE.search(req)
534 result_key = 'depends'
535535 if m:
536536 section = m.group('section')
537537 if section:
543543 result_key = 'suggests'
544544 else:
545545 continue
546 else:
547 result_key = 'depends'
548546 dependency = guess_deps(req=req)
549547 if dependency:
550548 result[result_key].append(dependency)
00 import os
1 import logging
12 import platform
23 import unittest
34 from copy import deepcopy
8485 requires = {}
8586 dist_info_metadata = {}
8687 options = FakeOptions()
88 parse = True
8789
8890 def setUp(self):
8991 self.d = Dependencies(self.pkg, self.impl)
115117 cleanup = prime_pydist(self.impl, self.pydist)
116118 self.addCleanup(cleanup)
117119
118 self.d.parse(stats, self.options)
120 if self.parse:
121 self.d.parse(stats, self.options)
122 else:
123 self.prepared_stats = stats
119124
120125 def assertNotInDepends(self, pkg):
121126 """Assert that pkg doesn't appear *anywhere* in self.d.depends"""
652657
653658 def test_ignores_pyversion_packages(self):
654659 self.assertNotInDepends('python-python-version-ge26')
660
661
662 class TestIgnoresUnusedModulesDistInfo(DependenciesTestCase):
663 options = FakeOptions(guess_deps=True, depends_section=['feature'])
664 dist_info_metadata = {
665 'debian/foo/usr/lib/python3/dist-packages/foo.dist-info/METADATA': (
666 "Requires-Dist: unusued-complex-module ; "
667 "(sys_platform == \"darwin\") and extra == 'nativelib'",
668 "Requires-Dist: unused-win-module ; (sys_platform == \"win32\")",
669 "Requires-Dist: unused-extra-module ; extra == 'unused'",
670 ),
671 }
672 parse = False
673
674 def test_ignores_unused_dependencies(self):
675 if not hasattr(self, 'assertLogs'):
676 raise unittest.SkipTest("Requires Python >= 3.4")
677 with self.assertLogs(logger='dhpython', level=logging.INFO) as logs:
678 self.d.parse(self.prepared_stats, self.options)
679 for line in logs.output:
680 self.assertTrue(
681 line.startswith(
682 'INFO:dhpython:Ignoring complex environment marker'),
683 'Expecting only complex environment marker messages, but '
684 'got: {}'.format(line))
685
686
687 class TestIgnoresUnusedModulesEggInfo(DependenciesTestCase):
688 options = FakeOptions(guess_deps=True, depends_section=['feature'])
689 requires = {
690 'debian/foo/usr/lib/python3/dist-packages/foo.egg-info/requires.txt': (
691 "[nativelib:(sys_platform == 'darwin')]",
692 "unusued-complex-module",
693 "[:sys_platform == 'win32']",
694 "unused-win-module",
695 "[unused]",
696 "unused-extra-module",
697 )
698 }
699 parse = False
700
701 def test_ignores_unused_dependencies(self):
702 if not hasattr(self, 'assertNoLogs'):
703 raise unittest.SkipTest("Requires Python >= 3.10")
704 with self.assertNoLogs(logger='dhpython', level=logging.INFO):
705 self.d.parse(self.prepared_stats, self.options)