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
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 | ||
0 | 7 | dh-python (5.20220102) unstable; urgency=medium |
1 | 8 | |
2 | 9 | * Allow passing arguments to tox tests. |
185 | 185 | 'or your upstream author to fix requires.txt') |
186 | 186 | raise Exception('requirement is not valid: %s' % req) |
187 | 187 | 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 | ||
188 | 202 | name = req_d['name'] |
189 | 203 | details = data.get(name.lower()) |
190 | env_marker_alts = '' | |
191 | 204 | if details: |
192 | 205 | for item in details: |
193 | 206 | if version and version not in item.get('versions', version): |
194 | 207 | # rule doesn't match version, try next one |
195 | 208 | 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 | ||
210 | 209 | if not item['dependency']: |
211 | 210 | return # this requirement should be ignored |
212 | 211 | if item['dependency'].endswith(')'): |
491 | 490 | else: |
492 | 491 | result_key = 'depends' |
493 | 492 | |
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): | |
498 | 497 | dependency = ', '.join( |
499 | 498 | part.strip() + ' ' + env_action |
500 | 499 | for part in dependency.split(',')) |
532 | 531 | requires = metadata.get_all('Requires-Dist', []) |
533 | 532 | for req in requires: |
534 | 533 | m = EXTRA_RE.search(req) |
534 | result_key = 'depends' | |
535 | 535 | if m: |
536 | 536 | section = m.group('section') |
537 | 537 | if section: |
543 | 543 | result_key = 'suggests' |
544 | 544 | else: |
545 | 545 | continue |
546 | else: | |
547 | result_key = 'depends' | |
548 | 546 | dependency = guess_deps(req=req) |
549 | 547 | if dependency: |
550 | 548 | result[result_key].append(dependency) |
0 | 0 | import os |
1 | import logging | |
1 | 2 | import platform |
2 | 3 | import unittest |
3 | 4 | from copy import deepcopy |
84 | 85 | requires = {} |
85 | 86 | dist_info_metadata = {} |
86 | 87 | options = FakeOptions() |
88 | parse = True | |
87 | 89 | |
88 | 90 | def setUp(self): |
89 | 91 | self.d = Dependencies(self.pkg, self.impl) |
115 | 117 | cleanup = prime_pydist(self.impl, self.pydist) |
116 | 118 | self.addCleanup(cleanup) |
117 | 119 | |
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 | |
119 | 124 | |
120 | 125 | def assertNotInDepends(self, pkg): |
121 | 126 | """Assert that pkg doesn't appear *anywhere* in self.d.depends""" |
652 | 657 | |
653 | 658 | def test_ignores_pyversion_packages(self): |
654 | 659 | 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) |