bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151)

(cherry picked from commit 109d966021)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
Miss Islington (bot) 2021-12-16 13:19:14 -08:00 committed by GitHub
parent 0194bbbee6
commit 09d7319bfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -669,7 +669,7 @@ class Distribution:
def make_condition(name): def make_condition(name):
return name and f'extra == "{name}"' return name and f'extra == "{name}"'
def parse_condition(section): def quoted_marker(section):
section = section or '' section = section or ''
extra, sep, markers = section.partition(':') extra, sep, markers = section.partition(':')
if extra and markers: if extra and markers:
@ -677,8 +677,17 @@ class Distribution:
conditions = list(filter(None, [markers, make_condition(extra)])) conditions = list(filter(None, [markers, make_condition(extra)]))
return '; ' + ' and '.join(conditions) if conditions else '' 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: 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): class DistributionFinder(MetaPathFinder):

View file

@ -235,6 +235,7 @@ class APITests(
[extra1] [extra1]
dep4 dep4
dep6@ git+https://example.com/python/dep.git@v1.0.0
[extra2:python_version < "3"] [extra2:python_version < "3"]
dep5 dep5
@ -247,6 +248,7 @@ class APITests(
'dep3; python_version < "3"', 'dep3; python_version < "3"',
'dep4; extra == "extra1"', 'dep4; extra == "extra1"',
'dep5; (python_version < "3") and extra == "extra2"', 'dep5; (python_version < "3") and extra == "extra2"',
'dep6@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1"',
] ]
# It's important that the environment marker expression be # It's important that the environment marker expression be
# wrapped in parentheses to avoid the following 'and' binding more # wrapped in parentheses to avoid the following 'and' binding more

View file

@ -0,0 +1,2 @@
Honor spec when generating requirement specs with urls and extras
(importlib_metadata 4.8.3).