Skip to content

Commit 09add11

Browse files
committed
bpo-46105: Honor spec when generating requirement specs with urls and extras.
1 parent ec6cb9a commit 09add11

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

Lib/importlib/metadata/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,16 +691,25 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
691691
def make_condition(name):
692692
return name and f'extra == "{name}"'
693693

694-
def parse_condition(section):
694+
def quoted_marker(section):
695695
section = section or ''
696696
extra, sep, markers = section.partition(':')
697697
if extra and markers:
698698
markers = f'({markers})'
699699
conditions = list(filter(None, [markers, make_condition(extra)]))
700700
return '; ' + ' and '.join(conditions) if conditions else ''
701701

702+
def url_req_space(req):
703+
"""
704+
PEP 508 requires a space between the url_spec and the quoted_marker.
705+
Ref python/importlib_metadata#357.
706+
"""
707+
# '@' is uniquely indicative of a url_req.
708+
return ' ' * ('@' in req)
709+
702710
for section in sections:
703-
yield section.value + parse_condition(section.name)
711+
space = url_req_space(section.value)
712+
yield section.value + space + quoted_marker(section.name)
704713

705714

706715
class DistributionFinder(MetaPathFinder):

Lib/test/test_importlib/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import Dict, Union
1313

1414
try:
15-
from importlib import resources
15+
from importlib import resources # type: ignore
1616

1717
getattr(resources, 'files')
1818
getattr(resources, 'as_file')

Lib/test/test_importlib/test_metadata_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ def test_more_complex_deps_requires_text(self):
233233
234234
[extra1]
235235
dep4
236+
dep6@ git+https://example.com/python/[email protected]
236237
237238
[extra2:python_version < "3"]
238239
dep5
@@ -245,6 +246,7 @@ def test_more_complex_deps_requires_text(self):
245246
'dep3; python_version < "3"',
246247
'dep4; extra == "extra1"',
247248
'dep5; (python_version < "3") and extra == "extra2"',
249+
'dep6@ git+https://example.com/python/[email protected] ; extra == "extra1"',
248250
]
249251
# It's important that the environment marker expression be
250252
# wrapped in parentheses to avoid the following 'and' binding more
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Honor spec when generating requirement specs with urls and extras
2+
(importlib_metadata 4.8.3).

0 commit comments

Comments
 (0)