Skip to content

Commit ccbccce

Browse files
committed
Refresh from importlib_metadata@cpython (0.15)
1 parent a1c3d9c commit ccbccce

File tree

7 files changed

+51
-50
lines changed

7 files changed

+51
-50
lines changed

‎Doc/library/importlib.metadata.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ interface expected of finders by Python's import system.
221221
an iterator over instances of the ``Distribution`` abstract class. This
222222
method must have the signature::
223223

224-
def find_distributions(name=None, path=sys.path):
224+
def find_distributions(name=None, path=None):
225225
"""Return an iterable of all Distribution instances capable of
226226
loading the metadata for packages matching the name
227227
(or all names if not supplied) along the paths in the list

‎Lib/importlib/metadata/__init__.py‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ class PackageNotFoundError(ModuleNotFoundError):
3535

3636

3737
class EntryPoint(collections.namedtuple('EntryPointBase', 'name value group')):
38-
"""An entry point as defined by Python packaging conventions."""
38+
"""An entry point as defined by Python packaging conventions.
39+
40+
See `the packaging docs on entry points
41+
<https://packaging.python.org/specifications/entry-points/>`_
42+
for more information.
43+
"""
3944

4045
pattern = re.compile(
4146
r'(?P<module>[\w.]+)\s*'
@@ -178,15 +183,6 @@ def _discover_resolvers():
178183
)
179184
return filter(None, declared)
180185

181-
@classmethod
182-
def find_local(cls):
183-
dists = itertools.chain.from_iterable(
184-
resolver(path=['.'])
185-
for resolver in cls._discover_resolvers()
186-
)
187-
dist, = dists
188-
return dist
189-
190186
@property
191187
def metadata(self):
192188
"""Return the parsed metadata for this Distribution.
@@ -309,8 +305,10 @@ class DistributionFinder(MetaPathFinder):
309305
@abc.abstractmethod
310306
def find_distributions(self, name=None, path=None):
311307
"""
308+
Find distributions.
309+
312310
Return an iterable of all Distribution instances capable of
313-
loading the metadata for packages matching the name
311+
loading the metadata for packages matching the ``name``
314312
(or all names if not supplied) along the paths in the list
315313
of directories ``path`` (defaults to sys.path).
316314
"""
@@ -347,14 +345,6 @@ def distributions():
347345
return Distribution.discover()
348346

349347

350-
def local_distribution():
351-
"""Get the ``Distribution`` instance for the package in CWD.
352-
353-
:return: A ``Distribution`` instance (or subclass thereof).
354-
"""
355-
return Distribution.find_local()
356-
357-
358348
def metadata(package):
359349
"""Get the metadata for the package.
360350

‎Lib/test/test_importlib/fixtures.py‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,28 @@ def tempdir_as_cwd():
4848

4949

5050
class SiteDir:
51+
def setUp(self):
52+
self.fixtures = ExitStack()
53+
self.addCleanup(self.fixtures.close)
54+
self.site_dir = self.fixtures.enter_context(tempdir())
55+
56+
57+
class OnSysPath:
5158
@staticmethod
5259
@contextlib.contextmanager
53-
def site_dir():
54-
with tempdir() as tmp:
55-
sys.path[:0] = [str(tmp)]
56-
try:
57-
yield tmp
58-
finally:
59-
sys.path.remove(str(tmp))
60+
def add_sys_path(dir):
61+
sys.path[:0] = [str(dir)]
62+
try:
63+
yield
64+
finally:
65+
sys.path.remove(str(dir))
6066

6167
def setUp(self):
62-
self.fixtures = ExitStack()
63-
self.addCleanup(self.fixtures.close)
64-
self.site_dir = self.fixtures.enter_context(self.site_dir())
68+
super(OnSysPath, self).setUp()
69+
self.fixtures.enter_context(self.add_sys_path(self.site_dir))
6570

6671

67-
class DistInfoPkg(SiteDir):
72+
class DistInfoPkg(OnSysPath, SiteDir):
6873
files = {
6974
"distinfo_pkg-1.0.0.dist-info": {
7075
"METADATA": """
@@ -91,7 +96,13 @@ def setUp(self):
9196
build_files(DistInfoPkg.files, self.site_dir)
9297

9398

94-
class EggInfoPkg(SiteDir):
99+
class DistInfoPkgOffPath(SiteDir):
100+
def setUp(self):
101+
super(DistInfoPkgOffPath, self).setUp()
102+
build_files(DistInfoPkg.files, self.site_dir)
103+
104+
105+
class EggInfoPkg(OnSysPath, SiteDir):
95106
files = {
96107
"egginfo_pkg.egg-info": {
97108
"PKG-INFO": """
@@ -128,7 +139,7 @@ def setUp(self):
128139
build_files(EggInfoPkg.files, prefix=self.site_dir)
129140

130141

131-
class EggInfoFile(SiteDir):
142+
class EggInfoFile(OnSysPath, SiteDir):
132143
files = {
133144
"egginfo_file.egg-info": """
134145
Metadata-Version: 1.0
@@ -149,14 +160,6 @@ def setUp(self):
149160
build_files(EggInfoFile.files, prefix=self.site_dir)
150161

151162

152-
class LocalPackage:
153-
def setUp(self):
154-
self.fixtures = ExitStack()
155-
self.addCleanup(self.fixtures.close)
156-
self.fixtures.enter_context(tempdir_as_cwd())
157-
build_files(EggInfoPkg.files)
158-
159-
160163
def build_files(file_defs, prefix=pathlib.Path()):
161164
"""Build a set of files/directories, as described by the
162165

‎Lib/test/test_importlib/test_main.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def test_resolve_without_attr(self):
5050
assert ep.load() is importlib.metadata
5151

5252

53-
class NameNormalizationTests(fixtures.SiteDir, unittest.TestCase):
53+
class NameNormalizationTests(
54+
fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
5455
@staticmethod
5556
def pkg_with_dashes(site_dir):
5657
"""
@@ -95,7 +96,7 @@ def test_dist_name_found_as_any_case(self):
9596
assert version(pkg_name.upper()) == '1.0'
9697

9798

98-
class NonASCIITests(fixtures.SiteDir, unittest.TestCase):
99+
class NonASCIITests(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
99100
@staticmethod
100101
def pkg_with_non_ascii_description(site_dir):
101102
"""
@@ -146,7 +147,7 @@ def test_package_discovery(self):
146147
assert all(
147148
isinstance(dist, Distribution)
148149
for dist in dists
149-
), dists
150+
)
150151
assert any(
151152
dist.metadata['Name'] == 'egginfo-pkg'
152153
for dist in dists

‎Lib/test/test_importlib/test_metadata_api.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import re
22
import textwrap
33
import unittest
4+
import itertools
45

56
from collections.abc import Iterator
67

78
from . import fixtures
89
from importlib.metadata import (
910
Distribution, PackageNotFoundError, distribution,
10-
entry_points, files, local_distribution, metadata, requires, version,
11+
entry_points, files, metadata, requires, version,
1112
)
1213

1314

@@ -138,7 +139,13 @@ def test_more_complex_deps_requires_text(self):
138139
assert deps == expected
139140

140141

141-
class LocalProjectTests(fixtures.LocalPackage, unittest.TestCase):
142-
def test_find_local(self):
143-
dist = local_distribution()
144-
assert dist.metadata['Name'] == 'egginfo-pkg'
142+
class OffSysPathTests(fixtures.DistInfoPkgOffPath, unittest.TestCase):
143+
def test_find_distributions_specified_path(self):
144+
dists = itertools.chain.from_iterable(
145+
resolver(path=[str(self.site_dir)])
146+
for resolver in Distribution._discover_resolvers()
147+
)
148+
assert any(
149+
dist.metadata['Name'] == 'distinfo-pkg'
150+
for dist in dists
151+
)

‎Lib/test/test_importlib/test_zip.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def setUp(self):
4848
egg = self.resources.enter_context(
4949
path(self.root, 'example-21.12-py3.6.egg'))
5050
sys.path.insert(0, str(egg))
51-
print('***', sys.path)
5251
self.resources.callback(sys.path.pop, 0)
5352

5453
def test_files(self):

‎Python.framework/Resources‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Resources

0 commit comments

Comments
 (0)