pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/967fddae2fe48f297563c358bdbdde1e2cfed4ee

faa60c69660fa.css" /> [3.8] bpo-41855: Fix duplicate results in FastPath.zip_children() (#2… · python/cpython@967fdda · GitHub
Skip to content

Commit 967fdda

Browse files
authored
[3.8] bpo-41855: Fix duplicate results in FastPath.zip_children() (#22404)
* bpo-41855: Backport fixes from importlib_metadata 1.5.2. * Add blurb. * Add anchor for finders and loaders
1 parent aeb66c1 commit 967fdda

5 files changed

Lines changed: 34 additions & 27 deletions

File tree

Doc/library/importlib.metadata.rst

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _using:
22

3-
==========================
4-
Using importlib.metadata
5-
==========================
3+
=================================
4+
Using :mod:`!importlib.metadata`
5+
=================================
66

77
.. note::
88
This functionality is provisional and may deviate from the usual
@@ -12,18 +12,18 @@
1212
package metadata. Built in part on Python's import system, this library
1313
intends to replace similar functionality in the `entry point
1414
API`_ and `metadata API`_ of ``pkg_resources``. Along with
15-
``importlib.resources`` in `Python 3.7
16-
and newer`_ (backported as `importlib_resources`_ for older versions of
15+
:mod:`importlib.resources` in Python 3.7
16+
and newer (backported as `importlib_resources`_ for older versions of
1717
Python), this can eliminate the need to use the older and less efficient
1818
``pkg_resources`` package.
1919

2020
By "installed package" we generally mean a third-party package installed into
2121
Python's ``site-packages`` directory via tools such as `pip
2222
<https://pypi.org/project/pip/>`_. Specifically,
2323
it means a package with either a discoverable ``dist-info`` or ``egg-info``
24-
directory, and metadata defined by `PEP 566`_ or its older specifications.
24+
directory, and metadata defined by :pep:`566` or its older specifications.
2525
By default, package metadata can live on the file system or in zip archives on
26-
``sys.path``. Through an extension mechanism, the metadata can live almost
26+
:data:`sys.path`. Through an extension mechanism, the metadata can live almost
2727
anywhere.
2828

2929

@@ -134,7 +134,7 @@ Distribution files
134134
You can also get the full set of files contained within a distribution. The
135135
``files()`` function takes a distribution package name and returns all of the
136136
files installed by this distribution. Each file object returned is a
137-
``PackagePath``, a `pathlib.Path`_ derived object with additional ``dist``,
137+
``PackagePath``, a :class:`pathlib.Path` derived object with additional ``dist``,
138138
``size``, and ``hash`` properties as indicated by the metadata. For example::
139139

140140
>>> util = [p for p in files('wheel') if 'util.py' in str(p)][0] # doctest: +SKIP
@@ -203,18 +203,18 @@ instance::
203203
>>> d.metadata['License'] # doctest: +SKIP
204204
'MIT'
205205

206-
The full set of available metadata is not described here. See `PEP 566
207-
<https://www.python.org/dev/peps/pep-0566/>`_ for additional details.
206+
The full set of available metadata is not described here. See :pep:`566`
207+
for additional details.
208208

209209

210210
Extending the search algorithm
211211
==============================
212212

213-
Because package metadata is not available through ``sys.path`` searches, or
213+
Because package metadata is not available through :data:`sys.path` searches, or
214214
package loaders directly, the metadata for a package is found through import
215-
system `finders`_. To find a distribution package's metadata,
216-
``importlib.metadata`` queries the list of `meta path finders`_ on
217-
`sys.meta_path`_.
215+
system :ref:`finders <finders-and-loaders>`. To find a distribution package's metadata,
216+
``importlib.metadata`` queries the list of :term:`meta path finders <meta path finder>` on
217+
:data:`sys.meta_path`.
218218

219219
The default ``PathFinder`` for Python includes a hook that calls into
220220
``importlib.metadata.MetadataPathFinder`` for finding distributions
@@ -224,7 +224,7 @@ The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the
224224
interface expected of finders by Python's import system.
225225
``importlib.metadata`` extends this protocol by looking for an optional
226226
``find_distributions`` callable on the finders from
227-
``sys.meta_path`` and presents this extended interface as the
227+
:data:`sys.meta_path` and presents this extended interface as the
228228
``DistributionFinder`` abstract base class, which defines this abstract
229229
method::
230230

@@ -247,20 +247,13 @@ a custom finder, return instances of this derived ``Distribution`` in the
247247

248248
.. _`entry point API`: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
249249
.. _`metadata API`: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#metadata-api
250-
.. _`Python 3.7 and newer`: https://docs.python.org/3/library/importlib.html#module-importlib.resources
251250
.. _`importlib_resources`: https://importlib-resources.readthedocs.io/en/latest/index.html
252-
.. _`PEP 566`: https://www.python.org/dev/peps/pep-0566/
253-
.. _`finders`: https://docs.python.org/3/reference/import.html#finders-and-loaders
254-
.. _`meta path finders`: https://docs.python.org/3/glossary.html#term-meta-path-finder
255-
.. _`sys.meta_path`: https://docs.python.org/3/library/sys.html#sys.meta_path
256-
.. _`pathlib.Path`: https://docs.python.org/3/library/pathlib.html#pathlib.Path
257251

258252

259253
.. rubric:: Footnotes
260254

261255
.. [#f1] Technically, the returned distribution metadata object is an
262-
`email.message.Message
263-
<https://docs.python.org/3/library/email.message.html#email.message.EmailMessage>`_
256+
:class:`email.message.EmailMessage`
264257
instance, but this is an implementation detail, and not part of the
265258
stable API. You should only use dictionary-like methods and syntax
266259
to access the metadata contents.

Doc/reference/import.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ named module, the two module objects will *not* be the same. By contrast,
202202
reinitialise the module contents by rerunning the module's code.
203203

204204

205+
.. _finders-and-loaders:
206+
205207
Finders and loaders
206208
-------------------
207209

Lib/importlib/metadata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ def zip_children(self):
408408
names = zip_path.root.namelist()
409409
self.joinpath = zip_path.joinpath
410410

411-
return (
412-
posixpath.split(child)[0]
411+
return dict.fromkeys(
412+
child.split(posixpath.sep, 1)[0]
413413
for child in names
414414
)
415415

@@ -475,7 +475,6 @@ def _search_paths(cls, name, paths):
475475
)
476476

477477

478-
479478
class PathDistribution(Distribution):
480479
def __init__(self, path):
481480
"""Construct a distribution from a path to the metadata directory.

Lib/test/test_importlib/test_zip.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
from contextlib import ExitStack
55
from importlib.metadata import (
6-
distribution, entry_points, files, PackageNotFoundError, version,
6+
distribution, entry_points, files, PackageNotFoundError,
7+
version, distributions,
78
)
89
from importlib.resources import path
910

11+
from test.support import requires_zlib
1012

13+
14+
@requires_zlib
1115
class TestZip(unittest.TestCase):
1216
root = 'test.test_importlib.data'
1317

@@ -46,7 +50,12 @@ def test_files(self):
4650
path = str(file.dist.locate_file(file))
4751
assert '.whl/' in path, path
4852

53+
def test_one_distribution(self):
54+
dists = list(distributions(path=sys.path[:1]))
55+
assert len(dists) == 1
56+
4957

58+
@requires_zlib
5059
class TestEgg(TestZip):
5160
def setUp(self):
5261
# Find the path to the example-*.egg so we can add it to the front of
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
In ``importlib.metadata``, fix issue where multiple children can be returned
2+
from ``FastPath.zip_children()``. Backport of
3+
`python-devs/importlib_metadata#117
4+
<https://gitlab.com/python-devs/importlib_metadata/-/issues/117>`_.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy