8000 bpo-46105: Honor spec when generating requirement specs with urls and… · python/cpython@109d966 · GitHub
[go: up one dir, main page]

Skip to content

Commit 109d966

Browse files
authored
bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151)
1 parent ecdc0cc commit 109d966

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Lib/importlib/metadata/__init__.py

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

672-
def parse_condition(section):
672+
def quoted_marker(section):
673673
section = section or ''
674674
extra, sep, markers = section.partition(':')
675675
if extra and markers:
676676
markers = f'({markers})'
677677
conditions = list(filter(None, [markers, make_condition(extra)]))
678678
return '; ' + ' and '.join(conditions) if conditions else ''
679679

680+
def url_req_space(req):
681+
"""
682+
PEP 508 requires a space between the url_spec and the quoted_marker.
683+
Ref python/importlib_metadata#357.
684+
"""
685+
# '@' is uniquely indicative of a url_req.
686+
return ' ' * ('@' in req)
687+
680688
for section in sections:
681-
yield section.value + parse_condition(section.name)
689+
space = url_req_space(section.value)
690+
yield section.value + space + quoted_marker(section.name)
682691

683692

684693
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
@@ -235,6 +235,7 @@ def test_more_complex_deps_requires_text(self):
235235
236236
[extra1]
237237
dep4
238+
dep6@ git+https://example.com/python/dep.git@v1.0.0
238239
239240
[extra2:python_version < "3"]
240241
dep5
@@ -247,6 +248,7 @@ def test_more_complex_deps_requires_text(self):
247248
'dep3; python_version < "3"',
248249
'dep4; extra == "extra1"',
249250
'dep5; (python_version < "3") and extra == "extra2"',
251+
'dep6@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1"',
250252
]
251253
# It's important that the environment marker expression be
252254
# 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)
0