Skip to content

Commit 177be52

Browse files
authored
[3.9] bpo-47004: Sync with importlib_metadata 4.11.3. (GH-31854). (GH-31859)
(cherry picked from commit b1e2868) Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
1 parent bda64b3 commit 177be52

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

Doc/library/importlib.metadata.rst

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ function::
199199
["pytest (>=3.0.0) ; extra == 'test'", "pytest-cov ; extra == 'test'"]
200200

201201

202+
.. _distributions:
203+
202204
Distributions
203205
=============
204206

Lib/importlib/metadata.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ class EntryPoint(
4545
See `the packaging docs on entry points
4646
<https://packaging.python.org/specifications/entry-points/>`_
4747
for more information.
48+
49+
>>> ep = EntryPoint(
50+
... name=None, group=None, value='package.module:attr [extra1, extra2]')
51+
>>> ep.module
52+
'package.module'
53+
>>> ep.attr
54+
'attr'
55+
>>> ep.extras
56+
['extra1', 'extra2']
4857
"""
4958

5059
pattern = re.compile(
@@ -91,7 +100,7 @@ def attr(self):
91100
@property
92101
def extras(self):
93102
match = self.pattern.match(self.value)
94-
return list(re.finditer(r'\w+', match.group('extras') or ''))
103+
return re.findall(r'\w+', match.group('extras') or '')
95104

96105
@classmethod
97106
def _from_config(cls, config):
@@ -308,7 +317,7 @@ def _read_dist_info_reqs(self):
308317

309318
def _read_egg_info_reqs(self):
310319
source = self.read_text('requires.txt')
311-
return source and self._deps_from_requires_text(source)
320+
return None if source is None else self._deps_from_requires_text(source)
312321

313322
@classmethod
314323
def _deps_from_requires_text(cls, source):

Lib/test/test_importlib/test_metadata_api.py

+10
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ def test_requires_egg_info(self):
104104
for dep in deps
105105
)
106106

107+
def test_requires_egg_info_empty(self):
108+
fixtures.build_files(
109+
{
110+
'requires.txt': '',
111+
},
112+
self.site_dir.joinpath('egginfo_pkg.egg-info'),
113+
)
114+
deps = requires('egginfo-pkg')
115+
assert deps == []
116+
107117
def test_requires_dist_info(self):
108118
deps = requires('distinfo-pkg')
109119
assert len(deps) == 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Apply bugfixes from importlib_metadata 4.11.3, including bugfix for
2+
EntryPoint.extras, which was returning match objects and not the extras
3+
strings.

0 commit comments

Comments
 (0)