]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Refresh from importlib_metadata@cpython (0.15) 12547/head
authorJason R. Coombs <jaraco@jaraco.com>
Fri, 24 May 2019 20:45:24 +0000 (16:45 -0400)
committerJason R. Coombs <jaraco@jaraco.com>
Fri, 24 May 2019 20:46:49 +0000 (16:46 -0400)
Doc/library/importlib.metadata.rst
Lib/importlib/metadata/__init__.py
Lib/test/test_importlib/fixtures.py
Lib/test/test_importlib/test_main.py
Lib/test/test_importlib/test_metadata_api.py
Lib/test/test_importlib/test_zip.py
Python.framework/Resources [new symlink]

index 416d8b6f707fc3b41c278afb64249f404f971499..3d10b5aeabfdc0c5744c09e4e996711e1a719b2d 100644 (file)
@@ -221,7 +221,7 @@ interface expected of finders by Python's import system.
 an iterator over instances of the ``Distribution`` abstract class. This
 method must have the signature::
 
-    def find_distributions(name=None, path=sys.path):
+    def find_distributions(name=None, path=None):
         """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
index 9a4ba6171cc8791acfcc62a93d523ee3ae5aac1b..24d45d2caad0ad13eb2f0466ff7ce3f62ceb52e4 100644 (file)
@@ -35,7 +35,12 @@ class PackageNotFoundError(ModuleNotFoundError):
 
 
 class EntryPoint(collections.namedtuple('EntryPointBase', 'name value group')):
-    """An entry point as defined by Python packaging conventions."""
+    """An entry point as defined by Python packaging conventions.
+
+    See `the packaging docs on entry points
+    <https://packaging.python.org/specifications/entry-points/>`_
+    for more information.
+    """
 
     pattern = re.compile(
         r'(?P<module>[\w.]+)\s*'
@@ -178,15 +183,6 @@ class Distribution:
             )
         return filter(None, declared)
 
-    @classmethod
-    def find_local(cls):
-        dists = itertools.chain.from_iterable(
-            resolver(path=['.'])
-            for resolver in cls._discover_resolvers()
-            )
-        dist, = dists
-        return dist
-
     @property
     def metadata(self):
         """Return the parsed metadata for this Distribution.
@@ -309,8 +305,10 @@ class DistributionFinder(MetaPathFinder):
     @abc.abstractmethod
     def find_distributions(self, name=None, path=None):
         """
+        Find distributions.
+
         Return an iterable of all Distribution instances capable of
-        loading the metadata for packages matching the name
+        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).
         """
@@ -347,14 +345,6 @@ def distributions():
     return Distribution.discover()
 
 
-def local_distribution():
-    """Get the ``Distribution`` instance for the package in CWD.
-
-    :return: A ``Distribution`` instance (or subclass thereof).
-    """
-    return Distribution.find_local()
-
-
 def metadata(package):
     """Get the metadata for the package.
 
index 00fcffa9d92d9892fa25ffae764365ff8bd11706..3b926ba26df779b60c81b7b4ff1a3abf7111e2ee 100644 (file)
@@ -48,23 +48,28 @@ def tempdir_as_cwd():
 
 
 class SiteDir:
+    def setUp(self):
+        self.fixtures = ExitStack()
+        self.addCleanup(self.fixtures.close)
+        self.site_dir = self.fixtures.enter_context(tempdir())
+
+
+class OnSysPath:
     @staticmethod
     @contextlib.contextmanager
-    def site_dir():
-        with tempdir() as tmp:
-            sys.path[:0] = [str(tmp)]
-            try:
-                yield tmp
-            finally:
-                sys.path.remove(str(tmp))
+    def add_sys_path(dir):
+        sys.path[:0] = [str(dir)]
+        try:
+            yield
+        finally:
+            sys.path.remove(str(dir))
 
     def setUp(self):
-        self.fixtures = ExitStack()
-        self.addCleanup(self.fixtures.close)
-        self.site_dir = self.fixtures.enter_context(self.site_dir())
+        super(OnSysPath, self).setUp()
+        self.fixtures.enter_context(self.add_sys_path(self.site_dir))
 
 
-class DistInfoPkg(SiteDir):
+class DistInfoPkg(OnSysPath, SiteDir):
     files = {
         "distinfo_pkg-1.0.0.dist-info": {
             "METADATA": """
@@ -91,7 +96,13 @@ class DistInfoPkg(SiteDir):
         build_files(DistInfoPkg.files, self.site_dir)
 
 
-class EggInfoPkg(SiteDir):
+class DistInfoPkgOffPath(SiteDir):
+    def setUp(self):
+        super(DistInfoPkgOffPath, self).setUp()
+        build_files(DistInfoPkg.files, self.site_dir)
+
+
+class EggInfoPkg(OnSysPath, SiteDir):
     files = {
         "egginfo_pkg.egg-info": {
             "PKG-INFO": """
@@ -128,7 +139,7 @@ class EggInfoPkg(SiteDir):
         build_files(EggInfoPkg.files, prefix=self.site_dir)
 
 
-class EggInfoFile(SiteDir):
+class EggInfoFile(OnSysPath, SiteDir):
     files = {
         "egginfo_file.egg-info": """
             Metadata-Version: 1.0
@@ -149,14 +160,6 @@ class EggInfoFile(SiteDir):
         build_files(EggInfoFile.files, prefix=self.site_dir)
 
 
-class LocalPackage:
-    def setUp(self):
-        self.fixtures = ExitStack()
-        self.addCleanup(self.fixtures.close)
-        self.fixtures.enter_context(tempdir_as_cwd())
-        build_files(EggInfoPkg.files)
-
-
 def build_files(file_defs, prefix=pathlib.Path()):
     """Build a set of files/directories, as described by the
 
index bb5c6760f555748ae99810eaebb50f71306d28db..b70f9440f6973a7f939ef65f03cdec3110b9d386 100644 (file)
@@ -50,7 +50,8 @@ class ImportTests(fixtures.DistInfoPkg, unittest.TestCase):
         assert ep.load() is importlib.metadata
 
 
-class NameNormalizationTests(fixtures.SiteDir, unittest.TestCase):
+class NameNormalizationTests(
+        fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
     @staticmethod
     def pkg_with_dashes(site_dir):
         """
@@ -95,7 +96,7 @@ class NameNormalizationTests(fixtures.SiteDir, unittest.TestCase):
         assert version(pkg_name.upper()) == '1.0'
 
 
-class NonASCIITests(fixtures.SiteDir, unittest.TestCase):
+class NonASCIITests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
     @staticmethod
     def pkg_with_non_ascii_description(site_dir):
         """
@@ -146,7 +147,7 @@ class DiscoveryTests(fixtures.EggInfoPkg,
         assert all(
             isinstance(dist, Distribution)
             for dist in dists
-            ), dists
+            )
         assert any(
             dist.metadata['Name'] == 'egginfo-pkg'
             for dist in dists
index 36c812da752dd09a57f2894fa6a687a97fa8537f..899777f4b1ad0178e6021c07232104bdf6fa36ab 100644 (file)
@@ -1,13 +1,14 @@
 import re
 import textwrap
 import unittest
+import itertools
 
 from collections.abc import Iterator
 
 from . import fixtures
 from importlib.metadata import (
     Distribution, PackageNotFoundError, distribution,
-    entry_points, files, local_distribution, metadata, requires, version,
+    entry_points, files, metadata, requires, version,
     )
 
 
@@ -138,7 +139,13 @@ class APITests(
         assert deps == expected
 
 
-class LocalProjectTests(fixtures.LocalPackage, unittest.TestCase):
-    def test_find_local(self):
-        dist = local_distribution()
-        assert dist.metadata['Name'] == 'egginfo-pkg'
+class OffSysPathTests(fixtures.DistInfoPkgOffPath, unittest.TestCase):
+    def test_find_distributions_specified_path(self):
+        dists = itertools.chain.from_iterable(
+            resolver(path=[str(self.site_dir)])
+            for resolver in Distribution._discover_resolvers()
+            )
+        assert any(
+            dist.metadata['Name'] == 'distinfo-pkg'
+            for dist in dists
+            )
index 22da01630810c8020d53e3f22ea7f508d30bad6c..db39e190ea7ac9d51033e8809f2ab147cfaa650f 100644 (file)
@@ -48,7 +48,6 @@ class TestEgg(TestZip):
         egg = self.resources.enter_context(
             path(self.root, 'example-21.12-py3.6.egg'))
         sys.path.insert(0, str(egg))
-        print('***', sys.path)
         self.resources.callback(sys.path.pop, 0)
 
     def test_files(self):
diff --git a/Python.framework/Resources b/Python.framework/Resources
new file mode 120000 (symlink)
index 0000000..953ee36
--- /dev/null
@@ -0,0 +1 @@
+Versions/Current/Resources
\ No newline at end of file