diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-09-12 10:29:11 +0100 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2019-09-12 16:12:02 +0100 |
commit | 3e206f4e1858fd4093124c8780f5021574b51d9d (patch) | |
tree | 059f9bb04343882615b924a9ac6cda29dc4fb2a0 /Lib/importlib/_bootstrap_external.py | |
parent | 36c29e444d6bc0e31b46509610d3fb7cff74f2c2 (diff) | |
download | cpython-git-backport-8ed6503-3.8.tar.gz |
[3.8] bpo-38121: Sync importlib.metadata with 0.22 backport (GH-15993)backport-8ed6503-3.8
* bpo-38121: Sync importlib.metadata with 0.22 backport
* 📜🤖 Added by blurb_it..
(cherry picked from commit 8ed6503eca4e3ea4949479d8d7fd9ffd54f81038)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Diffstat (limited to 'Lib/importlib/_bootstrap_external.py')
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 52 |
1 files changed, 3 insertions, 49 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index ba78c57eeb..b8ac482994 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1369,7 +1369,7 @@ class PathFinder: return spec.loader @classmethod - def find_distributions(self, context=None): + def find_distributions(cls, *args, **kwargs): """ Find distributions. @@ -1378,54 +1378,8 @@ class PathFinder: (or all names if ``None`` indicated) along the paths in the list of directories ``context.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 - def _search_paths(cls, pattern, paths): - """Find metadata directories in paths heuristically.""" - import itertools - return itertools.chain.from_iterable( - cls._search_path(path, pattern) - for path in map(cls._switch_path, paths) - ) - - @staticmethod - def _switch_path(path): - from contextlib import suppress - import zipfile - import pathlib - PYPY_OPEN_BUG = False - if not PYPY_OPEN_BUG or os.path.isfile(path): # pragma: no branch - with suppress(Exception): - return zipfile.Path(path) - return pathlib.Path(path) - - @classmethod - def _matches_info(cls, normalized, item): - import re - template = r'{pattern}(-.*)?\.(dist|egg)-info' - manifest = template.format(pattern=normalized) - return re.match(manifest, item.name, flags=re.IGNORECASE) - - @classmethod - def _matches_legacy(cls, normalized, item): - import re - template = r'{pattern}-.*\.egg[\\/]EGG-INFO' - manifest = template.format(pattern=normalized) - return re.search(manifest, str(item), flags=re.IGNORECASE) - - @classmethod - def _search_path(cls, root, pattern): - if not root.is_dir(): - return () - normalized = pattern.replace('-', '_') - return (item for item in root.iterdir() - if cls._matches_info(normalized, item) - or cls._matches_legacy(normalized, item)) + from importlib.metadata import MetadataPathFinder + return MetadataPathFinder.find_distributions(*args, **kwargs) class FileFinder: |