[3.9] bpo-47004: Sync with importlib_metadata 4.11.3. (GH-31854). (GH-31859)

(cherry picked from commit b1e2868607)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
Jason R. Coombs 2022-03-13 17:30:07 -04:00 committed by GitHub
parent bda64b3c0c
commit 177be52517
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View file

@ -199,6 +199,8 @@ function::
["pytest (>=3.0.0) ; extra == 'test'", "pytest-cov ; extra == 'test'"] ["pytest (>=3.0.0) ; extra == 'test'", "pytest-cov ; extra == 'test'"]
.. _distributions:
Distributions Distributions
============= =============

View file

@ -45,6 +45,15 @@ class EntryPoint(
See `the packaging docs on entry points See `the packaging docs on entry points
<https://packaging.python.org/specifications/entry-points/>`_ <https://packaging.python.org/specifications/entry-points/>`_
for more information. 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( pattern = re.compile(
@ -91,7 +100,7 @@ def attr(self):
@property @property
def extras(self): def extras(self):
match = self.pattern.match(self.value) 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 @classmethod
def _from_config(cls, config): def _from_config(cls, config):
@ -308,7 +317,7 @@ def _read_dist_info_reqs(self):
def _read_egg_info_reqs(self): def _read_egg_info_reqs(self):
source = self.read_text('requires.txt') 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 @classmethod
def _deps_from_requires_text(cls, source): def _deps_from_requires_text(cls, source):

View file

@ -104,6 +104,16 @@ def test_requires_egg_info(self):
for dep in deps 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): def test_requires_dist_info(self):
deps = requires('distinfo-pkg') deps = requires('distinfo-pkg')
assert len(deps) == 2 assert len(deps) == 2

View file

@ -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.