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>
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 @@
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 @@
"""
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 @@
)
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 @@
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 @@
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 PathDistribution(Distribution):
def __init__(self, path):
"""Construct a distribution from a path to the metadata directory.