Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
102e9b40
Commit
102e9b40
authored
Sep 02, 2019
by
Jason R. Coombs
Committed by
GitHub
Sep 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38010 Sync importlib.metadata with importlib_metadata 0.20. (GH-15646)
Sync importlib.metadata with importlib_metadata 0.20.
parent
1f21eaa1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
3 deletions
+25
-3
Doc/library/importlib.metadata.rst
Doc/library/importlib.metadata.rst
+7
-0
Lib/importlib/metadata.py
Lib/importlib/metadata.py
+15
-3
Lib/test/test_importlib/test_metadata_api.py
Lib/test/test_importlib/test_metadata_api.py
+2
-0
Misc/NEWS.d/next/Library/2019-09-02-14-30-39.bpo-38010.JOnz9Z.rst
...S.d/next/Library/2019-09-02-14-30-39.bpo-38010.JOnz9Z.rst
+1
-0
No files found.
Doc/library/importlib.metadata.rst
View file @
102e9b40
...
@@ -158,6 +158,13 @@ Once you have the file, you can also read its contents::
...
@@ -158,6 +158,13 @@ Once you have the file, you can also read its contents::
return s.encode('
utf
-
8
')
return s.encode('
utf
-
8
')
return s
return s
In the case where the metadata file listing files
(RECORD or SOURCES.txt) is missing, ``files()`` will
return ``None``. The caller may wish to wrap calls to
``files()`` in `always_iterable
<https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.always_iterable>`_
or otherwise guard against this condition if the target
distribution is not known to have the metadata present.
.. _requirements:
.. _requirements:
...
...
Lib/importlib/metadata.py
View file @
102e9b40
...
@@ -213,6 +213,15 @@ class Distribution:
...
@@ -213,6 +213,15 @@ class Distribution:
@property
@property
def files(self):
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()
file_lines = self._read_files_distinfo() or self._read_files_egginfo()
def make_file(name, hash=None, size_str=None):
def make_file(name, hash=None, size_str=None):
...
@@ -245,8 +254,7 @@ class Distribution:
...
@@ -245,8 +254,7 @@ class Distribution:
return self._read_dist_info_reqs() or self._read_egg_info_reqs()
return self._read_dist_info_reqs() or self._read_egg_info_reqs()
def _read_dist_info_reqs(self):
def _read_dist_info_reqs(self):
spec = self.metadata['Requires-Dist']
return self.metadata.get_all('Requires-Dist')
return spec and filter(None, spec.splitlines())
def _read_egg_info_reqs(self):
def _read_egg_info_reqs(self):
source = self.read_text('requires.txt')
source = self.read_text('requires.txt')
...
@@ -318,7 +326,11 @@ class DistributionFinder(MetaPathFinder):
...
@@ -318,7 +326,11 @@ class DistributionFinder(MetaPathFinder):
class PathDistribution(Distribution):
class PathDistribution(Distribution):
def __init__(self, path):
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
self._path = path
def read_text(self, filename):
def read_text(self, filename):
...
...
Lib/test/test_importlib/test_metadata_api.py
View file @
102e9b40
...
@@ -109,6 +109,8 @@ class APITests(
...
@@ -109,6 +109,8 @@ class APITests(
def test_requires_dist_info(self):
def test_requires_dist_info(self):
deps = list(requires('
distinfo
-
pkg
'))
deps = list(requires('
distinfo
-
pkg
'))
assert deps and all(deps)
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):
def test_more_complex_deps_requires_text(self):
requires = textwrap.dedent("""
requires = textwrap.dedent("""
...
...
Misc/NEWS.d/next/Library/2019-09-02-14-30-39.bpo-38010.JOnz9Z.rst
0 → 100644
View file @
102e9b40
In ``importlib.metadata`` sync with ``importlib_metadata`` 0.20, clarifying behavior of ``files()`` and fixing issue where only one requirement was returned for ``requires()`` on ``dist-info`` packages.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment