Ignore environment markers for Python 2.7, our logic is specific to 3.x.
Stefano Rivera
2 years ago
0 | dh-python (5.20211217) UNRELEASED; urgency=medium | |
1 | ||
2 | * Ignore environment markers for Python 2.7, our logic is specific to 3.x. | |
3 | ||
4 | -- Stefano Rivera <stefanor@debian.org> Fri, 17 Dec 2021 11:40:23 -0400 | |
5 | ||
0 | 6 | dh-python (5.20211216) unstable; urgency=medium |
1 | 7 | |
2 | 8 | * Use a consistent distribution name regexp to handle dashed names |
214 | 214 | req, |
215 | 215 | req_d['environment_marker'], |
216 | 216 | req_d['environment_marker_op'], |
217 | req_d['environment_marker_value']) | |
217 | req_d['environment_marker_value'], | |
218 | impl) | |
218 | 219 | if action is False: |
219 | 220 | return |
220 | 221 | elif action is True: |
308 | 309 | # return pname |
309 | 310 | |
310 | 311 | |
311 | def check_environment_marker_restrictions(req, marker, op, value): | |
312 | def check_environment_marker_restrictions(req, marker, op, value, impl): | |
312 | 313 | """Check wither we should include or skip a dependency based on its |
313 | 314 | environment markers. |
314 | 315 | |
316 | 317 | False - to skip it |
317 | 318 | str - to append "| foo" to generated dependencies |
318 | 319 | """ |
320 | if impl != 'cpython3': | |
321 | log.info('Ignoring environment markers for non-Python 3.x: %s', req) | |
322 | return False | |
323 | ||
319 | 324 | # TODO: Replace with an AST that can handle complex logic |
320 | 325 | if ' or ' in value or ' and ' in value: |
321 | 326 | log.info('Ignoring complex environment marker: %s', req) |
476 | 481 | line, |
477 | 482 | m.group('environment_marker'), |
478 | 483 | m.group('environment_marker_op'), |
479 | m.group('environment_marker_value')) | |
484 | m.group('environment_marker_value'), | |
485 | impl) | |
480 | 486 | processed.append(line) |
481 | 487 | continue |
482 | 488 | if section: |
5 | 5 | from tempfile import TemporaryDirectory |
6 | 6 | |
7 | 7 | from dhpython.depends import Dependencies |
8 | from dhpython.version import Version | |
8 | 9 | |
9 | 10 | |
10 | 11 | def pep386(d): |
12 | """Mark all pydist entries as being PEP386""" | |
11 | 13 | for k, v in d.items(): |
12 | 14 | if isinstance(v, str): |
13 | d[k] = {'dependency': v, 'standard': 'PEP386'} | |
15 | d[k] = {'dependency': v} | |
16 | d[k].setdefault('standard', 'PEP386') | |
17 | return d | |
18 | ||
19 | ||
20 | def py27(d): | |
21 | """Mark all pydist entries as being for Python 2.7""" | |
22 | for k, v in d.items(): | |
23 | if isinstance(v, str): | |
24 | d[k] = {'dependency': v} | |
25 | d[k].setdefault('versions', {Version('2.7')}) | |
14 | 26 | return d |
15 | 27 | |
16 | 28 | |
584 | 596 | |
585 | 597 | def test_depends_on_un_marked_dependency_after_extra(self): |
586 | 598 | raise unittest.SkipTest('Not possible in requires.txt') |
599 | ||
600 | ||
601 | class TestEnvironmentMarkers27EggInfo(DependenciesTestCase): | |
602 | options = FakeOptions(guess_deps=True) | |
603 | impl = 'cpython2' | |
604 | requires = { | |
605 | 'debian/foo/usr/lib/python2.7/dist-packages/foo.egg-info/requires.txt': ( | |
606 | "no_markers", | |
607 | "[:os_name == 'posix']", | |
608 | "os_posix", | |
609 | "[:python_version >= '2.6']", | |
610 | "python_version_ge26", | |
611 | ) | |
612 | } | |
613 | pydist = py27({ | |
614 | 'no_markers': 'python-no-markers', | |
615 | 'os_posix': 'python-os-posix', | |
616 | 'python_version_ge26': 'python-python-version-ge26', | |
617 | }) | |
618 | ||
619 | def test_depends_on_unmarked_packages(self): | |
620 | self.assertIn('python-no-markers', self.d.depends) | |
621 | ||
622 | def test_ignores_posix_packages(self): | |
623 | self.assertNotInDepends('python-os-posix') | |
624 | ||
625 | def test_ignores_pyversion_packages(self): | |
626 | self.assertNotInDepends('python-python-version-ge26') |