diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-17 00:58:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-17 00:58:19 (GMT) |
commit | 864ec170e14b663f999eb415a4f1a0067ec6833a (patch) | |
tree | c9912a296fab2ffe24a1ebf94107035209d960f8 /Lib/importlib/metadata.py | |
parent | 4c1effaaee472cc67f3186411a3df4f39af3d71a (diff) | |
download | cpython-864ec170e14b663f999eb415a4f1a0067ec6833a.zip cpython-864ec170e14b663f999eb415a4f1a0067ec6833a.tar.gz cpython-864ec170e14b663f999eb415a4f1a0067ec6833a.tar.bz2 |
[3.9] bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH-30151). (GH-30157)
(cherry picked from commit 109d96602199a91e94eb14b8cb3720841f22ded7)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Diffstat (limited to 'Lib/importlib/metadata.py')
-rw-r--r-- | Lib/importlib/metadata.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/importlib/metadata.py b/Lib/importlib/metadata.py index c6c7d31..594986c 100644 --- a/Lib/importlib/metadata.py +++ b/Lib/importlib/metadata.py @@ -344,17 +344,26 @@ class Distribution: def make_condition(name): return name and 'extra == "{name}"'.format(name=name) - def parse_condition(section): + def quoted_marker(section): section = section or '' extra, sep, markers = section.partition(':') if extra and markers: - markers = '({markers})'.format(markers=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, deps in sections.items(): for dep in deps: - yield dep + parse_condition(section) + space = url_req_space(dep) + yield dep + space + quoted_marker(section) class DistributionFinder(MetaPathFinder): |