]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-46105: Honor spec when generating requirement specs with urls and extras...
authorJason R. Coombs <jaraco@jaraco.com>
Fri, 17 Dec 2021 00:58:19 +0000 (19:58 -0500)
committerGitHub <noreply@github.com>
Fri, 17 Dec 2021 00:58:19 +0000 (19:58 -0500)
(cherry picked from commit 109d96602199a91e94eb14b8cb3720841f22ded7)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Lib/importlib/metadata.py
Lib/test/test_importlib/test_metadata_api.py
Misc/NEWS.d/next/Library/2021-12-16-14-30-36.bpo-46105.pprB1K.rst [new file with mode: 0644]

index c6c7d31aa5d8ae0bccfd571ac7a5e259d6d3b86e..594986ce23efab31b0c307e8497c64423bca46b6 100644 (file)
@@ -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):
index 1d7b29ae05fd10c8a42d8e88899123b3776fe220..420fbfeb3a704c02542888164d9e3f48563f575b 100644 (file)
@@ -121,6 +121,7 @@ class APITests(
 
             [extra1]
             dep4
+            dep6@ git+https://example.com/python/dep.git@v1.0.0
 
             [extra2:python_version < "3"]
             dep5
@@ -132,6 +133,7 @@ class APITests(
             'dep3; python_version < "3"',
             'dep4; extra == "extra1"',
             '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
         # wrapped in parentheses to avoid the following 'and' binding more
diff --git a/Misc/NEWS.d/next/Library/2021-12-16-14-30-36.bpo-46105.pprB1K.rst b/Misc/NEWS.d/next/Library/2021-12-16-14-30-36.bpo-46105.pprB1K.rst
new file mode 100644 (file)
index 0000000..145edcc
--- /dev/null
@@ -0,0 +1,2 @@
+Honor spec when generating requirement specs with urls and extras
+(importlib_metadata 4.8.3).