]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46105: Honor spec when generating requirement specs with urls and extras. (GH...
authorJason R. Coombs <jaraco@jaraco.com>
Thu, 16 Dec 2021 20:48:35 +0000 (15:48 -0500)
committerGitHub <noreply@github.com>
Thu, 16 Dec 2021 20:48:35 +0000 (15:48 -0500)
Lib/importlib/metadata/__init__.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 b3e8fb05f1d985cf7ad4a1f4645a91aaf00dac98..ec41ed39157a930cf8b7dad7a901185f1983d2d1 100644 (file)
@@ -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):
index dc9c234d15b7858ae4d9b300d721c11d582e58a2..4a45312e31cd587ec6499d5880f8143990ba35ac 100644 (file)
@@ -235,6 +235,7 @@ class APITests(
 
             [extra1]
             dep4
+            dep6@ git+https://example.com/python/dep.git@v1.0.0
 
             [extra2:python_version < "3"]
             dep5
@@ -247,6 +248,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).