]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-47004: Sync with importlib_metadata 4.11.3. (#31854)
authorJason R. Coombs <jaraco@jaraco.com>
Sun, 13 Mar 2022 19:53:29 +0000 (15:53 -0400)
committerGitHub <noreply@github.com>
Sun, 13 Mar 2022 19:53:29 +0000 (15:53 -0400)
Doc/library/importlib.metadata.rst
Lib/importlib/metadata/__init__.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 50fc904535b09b4e07503558372e4eb8c1684afc..a6caa994497ba807dc321d6b058e7a8518755711 100644 (file)
@@ -264,6 +264,7 @@ Python packages or modules::
 
 .. versionadded:: 3.10
 
+.. _distributions:
 
 Distributions
 =============
index 9fd6e04ae9abf19b154de58fc5800fb0812fad8d..9ceae8a0e04b5a96ce694625f5891bd7f25612f6 100644 (file)
@@ -152,6 +152,15 @@ class EntryPoint(DeprecatedTuple):
     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(
@@ -203,7 +212,7 @@ class EntryPoint(DeprecatedTuple):
     @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 '')
 
     def _for(self, dist):
         vars(self).update(dist=dist)
@@ -221,6 +230,25 @@ class EntryPoint(DeprecatedTuple):
         return iter((self.name, self))
 
     def matches(self, **params):
+        """
+        EntryPoint matches the given parameters.
+
+        >>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]')
+        >>> ep.matches(group='foo')
+        True
+        >>> ep.matches(name='bar', value='bing:bong [extra1, extra2]')
+        True
+        >>> ep.matches(group='foo', name='other')
+        False
+        >>> ep.matches()
+        True
+        >>> ep.matches(extras=['extra1', 'extra2'])
+        True
+        >>> ep.matches(module='bing')
+        True
+        >>> ep.matches(attr='bong')
+        True
+        """
         attrs = (getattr(self, param) for param in params)
         return all(map(operator.eq, params.values(), attrs))
 
@@ -292,21 +320,15 @@ class DeprecatedList(list):
             self._warn()
             return getattr(super(), method_name)(*args, **kwargs)
 
-        return wrapped
-
-    for method_name in [
-        '__setitem__',
-        '__delitem__',
-        'append',
-        'reverse',
-        'extend',
-        'pop',
-        'remove',
-        '__iadd__',
-        'insert',
-        'sort',
-    ]:
-        locals()[method_name] = _wrap_deprecated_method(method_name)
+        return method_name, wrapped
+
+    locals().update(
+        map(
+            _wrap_deprecated_method,
+            '__setitem__ __delitem__ append reverse extend pop remove '
+            '__iadd__ insert sort'.split(),
+        )
+    )
 
     def __add__(self, other):
         if not isinstance(other, tuple):
@@ -660,7 +682,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 pass_none(self._deps_from_requires_text)(source)
 
     @classmethod
     def _deps_from_requires_text(cls, source):
@@ -765,7 +787,6 @@ class FastPath:
 
     def __init__(self, root):
         self.root = root
-        self.base = os.path.basename(self.root).lower()
 
     def joinpath(self, child):
         return pathlib.Path(self.root, child)
index 78287c314ced72586413e1e8145a0d939e391e8e..b3627cbb75bd7b43467b2bab540a3a965ec8f363 100644 (file)
@@ -220,6 +220,16 @@ class APITests(
         assert len(deps) == 2
         assert any(dep == 'wheel >= 1.0; python_version >= "2.7"' 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.