Skip to content

Commit 441c69b

Browse files
committed
[3.9] bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151).
(cherry picked from commit 109d966) Co-authored-by: Jason R. Coombs <[email protected]>
1 parent 4c1effa commit 441c69b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Lib/importlib/metadata.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,25 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
344344
def make_condition(name):
345345
return name and 'extra == "{name}"'.format(name=name)
346346

347-
def parse_condition(section):
347+
def quoted_marker(section):
348348
section = section or ''
349349
extra, sep, markers = section.partition(':')
350350
if extra and markers:
351-
markers = '({markers})'.format(markers=markers)
351+
markers = f'({markers})'
352352
conditions = list(filter(None, [markers, make_condition(extra)]))
353353
return '; ' + ' and '.join(conditions) if conditions else ''
354354

355-
for section, deps in sections.items():
356-
for dep in deps:
357-
yield dep + parse_condition(section)
355+
def url_req_space(req):
356+
"""
357+
PEP 508 requires a space between the url_spec and the quoted_marker.
358+
Ref python/importlib_metadata#357.
359+
"""
360+
# '@' is uniquely indicative of a url_req.
361+
return ' ' * ('@' in req)
362+
363+
for section in sections:
364+
space = url_req_space(section.value)
365+
yield section.value + space + quoted_marker(section.name)
358366

359367

360368
class DistributionFinder(MetaPathFinder):

Lib/test/test_importlib/test_metadata_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def test_more_complex_deps_requires_text(self):
121121
122122
[extra1]
123123
dep4
124+
dep6@ git+https://example.com/python/[email protected]
124125
125126
[extra2:python_version < "3"]
126127
dep5
@@ -132,6 +133,7 @@ def test_more_complex_deps_requires_text(self):
132133
'dep3; python_version < "3"',
133134
'dep4; extra == "extra1"',
134135
'dep5; (python_version < "3") and extra == "extra2"',
136+
'dep6@ git+https://example.com/python/[email protected] ; extra == "extra1"',
135137
]
136138
# It's important that the environment marker expression be
137139
# 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)