]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-47004: Sync with importlib_metadata 4.11.3. (GH-31854). (GH-31859)
authorJason R. Coombs <jaraco@jaraco.com>
Sun, 13 Mar 2022 21:30:07 +0000 (17:30 -0400)
committerGitHub <noreply@github.com>
Sun, 13 Mar 2022 21:30:07 +0000 (17:30 -0400)
(cherry picked from commit b1e286860742e7ba6fadc75e3ddb6c2899a56919)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Doc/library/importlib.metadata.rst
Lib/importlib/metadata.py
Lib/test/test_importlib/test_metadata_api.py
Misc/NEWS.d/next/Library/2022-03-13-15-04-05.bpo-47004.SyYpxd.rst [new file with mode: 0644]

index 1f73017e05ced7aa2adb109a9a671e3f4fdd8d84..7652d501d9d917c6c2f3f2e6ec73c4ad10f6e4d0 100644 (file)
@@ -199,6 +199,8 @@ function::
     ["pytest (>=3.0.0) ; extra == 'test'", "pytest-cov ; extra == 'test'"]
 
 
+.. _distributions:
+
 Distributions
 =============
 
index 7b8038fd63a8478943eba8ede25a9b99264a6585..647fd3e4dbf8baeca76bc3b1fe2ebeb3387cb1c4 100644 (file)
@@ -45,6 +45,15 @@ class EntryPoint(
     See `the packaging docs on entry points
     <https://packaging.python.org/specifications/entry-points/>`_
     for more information.
+
+    >>> ep = EntryPoint(
+    ...     name=None, group=None, value='package.module:attr [extra1, extra2]')
+    >>> ep.module
+    'package.module'
+    >>> ep.attr
+    'attr'
+    >>> ep.extras
+    ['extra1', 'extra2']
     """
 
     pattern = re.compile(
@@ -91,7 +100,7 @@ class EntryPoint(
     @property
     def extras(self):
         match = self.pattern.match(self.value)
-        return list(re.finditer(r'\w+', match.group('extras') or ''))
+        return re.findall(r'\w+', match.group('extras') or '')
 
     @classmethod
     def _from_config(cls, config):
@@ -308,7 +317,7 @@ class Distribution:
 
     def _read_egg_info_reqs(self):
         source = self.read_text('requires.txt')
-        return source and self._deps_from_requires_text(source)
+        return None if source is None else self._deps_from_requires_text(source)
 
     @classmethod
     def _deps_from_requires_text(cls, source):
index 420fbfeb3a704c02542888164d9e3f48563f575b..cba920ab02c872eb858dd7cf71aecc86db7e0e5d 100644 (file)
@@ -104,6 +104,16 @@ class APITests(
             for dep in deps
             )
 
+    def test_requires_egg_info_empty(self):
+        fixtures.build_files(
+            {
+                'requires.txt': '',
+            },
+            self.site_dir.joinpath('egginfo_pkg.egg-info'),
+        )
+        deps = requires('egginfo-pkg')
+        assert deps == []
+
     def test_requires_dist_info(self):
         deps = requires('distinfo-pkg')
         assert len(deps) == 2
diff --git a/Misc/NEWS.d/next/Library/2022-03-13-15-04-05.bpo-47004.SyYpxd.rst b/Misc/NEWS.d/next/Library/2022-03-13-15-04-05.bpo-47004.SyYpxd.rst
new file mode 100644 (file)
index 0000000..3cb3b21
--- /dev/null
@@ -0,0 +1,3 @@
+Apply bugfixes from importlib_metadata 4.11.3, including bugfix for
+EntryPoint.extras, which was returning match objects and not the extras
+strings.