bpo-38086: Sync importlib.metadata with importlib_metadata 0.21. (GH-15840)

https://gitlab.com/python-devs/importlib_metadata/-/tags/0.21
This commit is contained in:
Jason R. Coombs 2019-09-10 14:53:31 +01:00 committed by Brett Cannon
parent 97d7906e30
commit 17499d8270
8 changed files with 712 additions and 661 deletions

View file

@ -1370,21 +1370,19 @@ class PathFinder:
return spec.loader
@classmethod
def find_distributions(cls, name=None, path=None):
def find_distributions(self, context=None):
"""
Find distributions.
Return an iterable of all Distribution instances capable of
loading the metadata for packages matching the ``name``
(or all names if not supplied) along the paths in the list
of directories ``path`` (defaults to sys.path).
loading the metadata for packages matching ``context.name``
(or all names if ``None`` indicated) along the paths in the list
of directories ``context.path``.
"""
import re
from importlib.metadata import PathDistribution
if path is None:
path = sys.path
pattern = '.*' if name is None else re.escape(name)
found = cls._search_paths(pattern, path)
from importlib.metadata import PathDistribution, DistributionFinder
if context is None:
context = DistributionFinder.Context()
found = self._search_paths(context.pattern, context.path)
return map(PathDistribution, found)
@classmethod