diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-09-02 15:08:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-02 15:08:03 (GMT) |
commit | 102e9b40ff6ee45086a5f0d34d9c60c581a1e5e5 (patch) | |
tree | 6000eb766999fabf5ccac8814c07d93ee146d248 /Lib | |
parent | 1f21eaa15e8a0d2b0f78d0e3f2b9e5b458eb0a70 (diff) | |
download | cpython-102e9b40ff6ee45086a5f0d34d9c60c581a1e5e5.zip cpython-102e9b40ff6ee45086a5f0d34d9c60c581a1e5e5.tar.gz cpython-102e9b40ff6ee45086a5f0d34d9c60c581a1e5e5.tar.bz2 |
bpo-38010 Sync importlib.metadata with importlib_metadata 0.20. (GH-15646)
Sync importlib.metadata with importlib_metadata 0.20.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/metadata.py | 18 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_metadata_api.py | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/Lib/importlib/metadata.py b/Lib/importlib/metadata.py index e80f4fa..3b46142 100644 --- a/Lib/importlib/metadata.py +++ b/Lib/importlib/metadata.py @@ -213,6 +213,15 @@ class Distribution: @property def files(self): + """Files in this distribution. + + :return: Iterable of PackagePath for this distribution or None + + Result is `None` if the metadata file that enumerates files + (i.e. RECORD for dist-info or SOURCES.txt for egg-info) is + missing. + Result may be empty if the metadata exists but is empty. + """ file_lines = self._read_files_distinfo() or self._read_files_egginfo() def make_file(name, hash=None, size_str=None): @@ -245,8 +254,7 @@ class Distribution: return self._read_dist_info_reqs() or self._read_egg_info_reqs() def _read_dist_info_reqs(self): - spec = self.metadata['Requires-Dist'] - return spec and filter(None, spec.splitlines()) + return self.metadata.get_all('Requires-Dist') def _read_egg_info_reqs(self): source = self.read_text('requires.txt') @@ -318,7 +326,11 @@ class DistributionFinder(MetaPathFinder): class PathDistribution(Distribution): def __init__(self, path): - """Construct a distribution from a path to the metadata directory.""" + """Construct a distribution from a path to the metadata directory. + + :param path: A pathlib.Path or similar object supporting + .joinpath(), __div__, .parent, and .read_text(). + """ self._path = path def read_text(self, filename): diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py index 899777f..af3bab3 100644 --- a/Lib/test/test_importlib/test_metadata_api.py +++ b/Lib/test/test_importlib/test_metadata_api.py @@ -109,6 +109,8 @@ class APITests( def test_requires_dist_info(self): deps = list(requires('distinfo-pkg')) assert deps and all(deps) + assert 'wheel >= 1.0' in deps + assert "pytest; extra == 'test'" in deps def test_more_complex_deps_requires_text(self): requires = textwrap.dedent(""" |