summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-06-05 20:34:16 (GMT)
committerGitHub <noreply@github.com>2020-06-05 20:34:16 (GMT)
commit161541ab45278df6603dd870113b10f13e4d9e16 (patch)
tree53d4dd1133a5912092faf71918550202864f2475 /Lib/importlib
parent5fe1df1886e2e53b04bf76ef916857271d3c8f20 (diff)
downloadcpython-161541ab45278df6603dd870113b10f13e4d9e16.zip
cpython-161541ab45278df6603dd870113b10f13e4d9e16.tar.gz
cpython-161541ab45278df6603dd870113b10f13e4d9e16.tar.bz2
bpo-39791: Refresh importlib.metadata from importlib_metadata 1.6.1. (GH-20659)
* Refresh importlib.metadata from importlib_metadata 1.6.1. * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/metadata.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/Lib/importlib/metadata.py b/Lib/importlib/metadata.py
index 831f593..ffa0cba 100644
--- a/Lib/importlib/metadata.py
+++ b/Lib/importlib/metadata.py
@@ -79,6 +79,16 @@ class EntryPoint(
return functools.reduce(getattr, attrs, module)
@property
+ def module(self):
+ match = self.pattern.match(self.value)
+ return match.group('module')
+
+ @property
+ def attr(self):
+ match = self.pattern.match(self.value)
+ return match.group('attr')
+
+ @property
def extras(self):
match = self.pattern.match(self.value)
return list(re.finditer(r'\w+', match.group('extras') or ''))
@@ -170,7 +180,7 @@ class Distribution:
"""
for resolver in cls._discover_resolvers():
dists = resolver(DistributionFinder.Context(name=name))
- dist = next(dists, None)
+ dist = next(iter(dists), None)
if dist is not None:
return dist
else:
@@ -213,6 +223,17 @@ class Distribution:
)
return filter(None, declared)
+ @classmethod
+ def _local(cls, root='.'):
+ from pep517 import build, meta
+ system = build.compat_system(root)
+ builder = functools.partial(
+ meta.build,
+ source_dir=root,
+ system=system,
+ )
+ return PathDistribution(zipfile.Path(meta.build_as_zip(builder)))
+
@property
def metadata(self):
"""Return the parsed metadata for this Distribution.
@@ -391,7 +412,7 @@ class FastPath:
def __init__(self, root):
self.root = root
- self.base = os.path.basename(root).lower()
+ self.base = os.path.basename(self.root).lower()
def joinpath(self, child):
return pathlib.Path(self.root, child)
@@ -408,8 +429,8 @@ class FastPath:
names = zip_path.root.namelist()
self.joinpath = zip_path.joinpath
- return (
- posixpath.split(child)[0]
+ return dict.fromkeys(
+ child.split(posixpath.sep, 1)[0]
for child in names
)
@@ -475,7 +496,6 @@ class MetadataPathFinder(DistributionFinder):
)
-
class PathDistribution(Distribution):
def __init__(self, path):
"""Construct a distribution from a path to the metadata directory.