Skip to content

[3.10] bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151) #30156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Lib/importlib/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,16 +669,25 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
def make_condition(name):
return name and f'extra == "{name}"'

def parse_condition(section):
def quoted_marker(section):
section = section or ''
extra, sep, markers = section.partition(':')
if extra and markers:
markers = f'({markers})'
conditions = list(filter(None, [markers, make_condition(extra)]))
return '; ' + ' and '.join(conditions) if conditions else ''

def url_req_space(req):
"""
PEP 508 requires a space between the url_spec and the quoted_marker.
Ref python/importlib_metadata#357.
"""
# '@' is uniquely indicative of a url_req.
return ' ' * ('@' in req)

for section in sections:
yield section.value + parse_condition(section.name)
space = url_req_space(section.value)
yield section.value + space + quoted_marker(section.name)


class DistributionFinder(MetaPathFinder):
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_importlib/test_metadata_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def test_more_complex_deps_requires_text(self):

[extra1]
dep4
dep6@ git+https://example.com/python/[email protected]

[extra2:python_version < "3"]
dep5
Expand All @@ -247,6 +248,7 @@ def test_more_complex_deps_requires_text(self):
'dep3; python_version < "3"',
'dep4; extra == "extra1"',
'dep5; (python_version < "3") and extra == "extra2"',
'dep6@ git+https://example.com/python/[email protected] ; extra == "extra1"',
]
# It's important that the environment marker expression be
# wrapped in parentheses to avoid the following 'and' binding more
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Honor spec when generating requirement specs with urls and extras
(importlib_metadata 4.8.3).