summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/metadata
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-12-16 20:48:35 (GMT)
committerGitHub <noreply@github.com>2021-12-16 20:48:35 (GMT)
commit109d96602199a91e94eb14b8cb3720841f22ded7 (patch)
tree44d76b7d8a6605fe150147810e064e2f195d82ab /Lib/importlib/metadata
parentecdc0ccede5f9ac4042ff56f295d81df2f428950 (diff)
downloadcpython-109d96602199a91e94eb14b8cb3720841f22ded7.zip
cpython-109d96602199a91e94eb14b8cb3720841f22ded7.tar.gz
cpython-109d96602199a91e94eb14b8cb3720841f22ded7.tar.bz2
bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151)
Diffstat (limited to 'Lib/importlib/metadata')
-rw-r--r--Lib/importlib/metadata/__init__.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
index b3e8fb0..ec41ed3 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -669,7 +669,7 @@ class Distribution:
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:
@@ -677,8 +677,17 @@ class Distribution:
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):