Skip to content

Commit d8aaa72

Browse files
committed
Only implement the extra space where it's required, fitting the spec more minimally.
1 parent 3b46c66 commit d8aaa72

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

importlib_metadata/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,16 +696,25 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
696696
def make_condition(name):
697697
return name and f'extra == "{name}"'
698698

699-
def parse_condition(section):
699+
def quoted_marker(section):
700700
section = section or ''
701701
extra, sep, markers = section.partition(':')
702702
if extra and markers:
703703
markers = f'({markers})'
704704
conditions = list(filter(None, [markers, make_condition(extra)]))
705-
return ' ; ' + ' and '.join(conditions) if conditions else ''
705+
return '; ' + ' and '.join(conditions) if conditions else ''
706+
707+
def url_req_space(req):
708+
"""
709+
PEP 508 requires a space between the url_spec and the quoted_marker.
710+
Ref python/importlib_metadata#357.
711+
"""
712+
# '@' is uniquely indicative of a url_req.
713+
return ' ' * ('@' in req)
706714

707715
for section in sections:
708-
yield section.value + parse_condition(section.name)
716+
space = url_req_space(section.value)
717+
yield section.value + space + quoted_marker(section.name)
709718

710719

711720
class DistributionFinder(MetaPathFinder):

tests/test_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,20 @@ def test_more_complex_deps_requires_text(self):
245245
246246
[extra1]
247247
dep4
248-
dep5@ git+https://example.com/python/[email protected]
248+
dep6@ git+https://example.com/python/[email protected]
249249
250250
[extra2:python_version < "3"]
251-
dep6
251+
dep5
252252
"""
253253
)
254254
deps = sorted(Distribution._deps_from_requires_text(requires))
255255
expected = [
256256
'dep1',
257257
'dep2',
258-
'dep3 ; python_version < "3"',
259-
'dep4 ; extra == "extra1"',
260-
'dep5@ git+https://example.com/python/[email protected] ; extra == "extra1"',
261-
'dep6 ; (python_version < "3") and extra == "extra2"',
258+
'dep3; python_version < "3"',
259+
'dep4; extra == "extra1"',
260+
'dep5; (python_version < "3") and extra == "extra2"',
261+
'dep6@ git+https://example.com/python/[email protected] ; extra == "extra1"',
262262
]
263263
# It's important that the environment marker expression be
264264
# wrapped in parentheses to avoid the following 'and' binding more

0 commit comments

Comments
 (0)