summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-03-13 21:29:50 (GMT)
committerGitHub <noreply@github.com>2022-03-13 21:29:50 (GMT)
commitd929aa70e2a324ea48fed221c3257f929be05115 (patch)
treeb46cde5b3f0c4aa17c50fae9b3e0551577e9de7c
parent25962e4e60235645f945d23281431b30b3c3d573 (diff)
downloadcpython-d929aa70e2a324ea48fed221c3257f929be05115.zip
cpython-d929aa70e2a324ea48fed221c3257f929be05115.tar.gz
cpython-d929aa70e2a324ea48fed221c3257f929be05115.tar.bz2
[3.10] bpo-47004: Sync with importlib_metadata 4.11.3. (GH-31854). (GH-31857)
(cherry picked from commit b1e286860742e7ba6fadc75e3ddb6c2899a56919) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
-rw-r--r--Doc/library/importlib.metadata.rst1
-rw-r--r--Lib/importlib/metadata/__init__.py33
-rw-r--r--Lib/test/test_importlib/test_metadata_api.py10
-rw-r--r--Misc/NEWS.d/next/Library/2022-03-13-15-04-05.bpo-47004.SyYpxd.rst3
4 files changed, 44 insertions, 3 deletions
diff --git a/Doc/library/importlib.metadata.rst b/Doc/library/importlib.metadata.rst
index 50fc904..a6caa99 100644
--- a/Doc/library/importlib.metadata.rst
+++ b/Doc/library/importlib.metadata.rst
@@ -264,6 +264,7 @@ Python packages or modules::
.. versionadded:: 3.10
+.. _distributions:
Distributions
=============
diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
index c7462f3..b3063cd 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -128,6 +128,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(
@@ -176,7 +185,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 '')
def _for(self, dist):
self.dist = dist
@@ -200,6 +209,25 @@ class EntryPoint(
)
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))
@@ -650,7 +678,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):
@@ -752,7 +780,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)
diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py
index 0890d6c..799f007 100644
--- a/Lib/test/test_importlib/test_metadata_api.py
+++ b/Lib/test/test_importlib/test_metadata_api.py
@@ -222,6 +222,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
index 0000000..3cb3b21
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-03-13-15-04-05.bpo-47004.SyYpxd.rst
@@ -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.