You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a47cd21
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: Doc/library/importlib.metadata.rst
+27-23Lines changed: 27 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ such as its entry points
19
19
or its top-level names (`Import Package <https://packaging.python.org/en/latest/glossary/#term-Import-Package>`_\s, modules, if any).
20
20
Built in part on Python's import system, this library
21
21
intends to replace similar functionality in the `entry point
22
-
API`_ and `metadata API`_ of ``pkg_resources``. Along with
22
+
API`_ and `metadata API`_ of ``pkg_resources``. Along with
23
23
:mod:`importlib.resources`,
24
24
this package can eliminate the need to use the older and less efficient
25
25
``pkg_resources`` package.
@@ -46,7 +46,7 @@ and metadata defined by the `Core metadata specifications <https://packaging.pyt
46
46
47
47
By default, distribution metadata can live on the file system
48
48
or in zip archives on
49
-
:data:`sys.path`. Through an extension mechanism, the metadata can live almost
49
+
:data:`sys.path`. Through an extension mechanism, the metadata can live almost
50
50
anywhere.
51
51
52
52
@@ -68,7 +68,7 @@ Overview
68
68
69
69
Let's say you wanted to get the version string for a
for more information on entry points, their definition, and usage.
173
173
@@ -240,12 +240,12 @@ number, as a string::
240
240
Distribution files
241
241
------------------
242
242
243
-
You can also get the full set of files contained within a distribution. The
243
+
You can also get the full set of files contained within a distribution. The
244
244
``files()`` function takes a `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_ name
245
245
and returns all of the
246
-
files installed by this distribution. Each file object returned is a
246
+
files installed by this distribution. Each file object returned is a
247
247
``PackagePath``, a :class:`pathlib.PurePath` derived object with additional ``dist``,
248
-
``size``, and ``hash`` properties as indicated by the metadata. For example::
248
+
``size``, and ``hash`` properties as indicated by the metadata. For example::
249
249
250
250
>>> util = [p for p in files('wheel') if 'util.py' in str(p)][0] # doctest: +SKIP
251
251
>>> util # doctest: +SKIP
@@ -321,9 +321,9 @@ Distributions
321
321
=============
322
322
323
323
While the above API is the most common and convenient usage, you can get all
324
-
of that information from the ``Distribution`` class. A ``Distribution`` is an
324
+
of that information from the ``Distribution`` class. A ``Distribution`` is an
325
325
abstract object that represents the metadata for
326
-
a Python `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_. You can
326
+
a Python `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_. You can
327
327
get the ``Distribution`` instance::
328
328
329
329
>>> from importlib.metadata import distribution # doctest: +SKIP
@@ -366,21 +366,26 @@ This metadata finder search defaults to ``sys.path``, but varies slightly in how
366
366
- ``importlib.metadata`` will incidentally honor :py:class:`pathlib.Path` objects on ``sys.path`` even though such values will be ignored for imports.
367
367
368
368
369
-
Extending the search algorithm
370
-
==============================
369
+
Implementing Custom Providers
370
+
=============================
371
+
372
+
``importlib.metadata`` address two API surfaces, one for *consumers*
373
+
and another for *providers*. Most users are consumers, consuming
374
+
metadata provided by the packages. There are other use-cases, however,
375
+
where users wish to expose metadata through some other mechanism,
376
+
such as alongside a custom importer. Such a use case calls for a
377
+
*custom provider*.
371
378
372
379
Because `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_ metadata
373
380
is not available through :data:`sys.path` searches, or
374
381
package loaders directly,
375
382
the metadata for a distribution is found through import
376
-
system :ref:`finders <finders-and-loaders>`. To find a distribution package's metadata,
383
+
system :ref:`finders <finders-and-loaders>`. To find a distribution package's metadata,
377
384
``importlib.metadata`` queries the list of :term:`meta path finders <meta path finder>` on
378
385
:data:`sys.meta_path`.
379
386
380
-
By default ``importlib.metadata`` installs a finder for distribution packages
381
-
found on the file system.
382
-
This finder doesn't actually find any *distributions*,
383
-
but it can find their metadata.
387
+
The implementation has hooks integrated into the ``PathFinder``,
388
+
serving metadata for distribution packages found on the file system.
384
389
385
390
The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the
386
391
interface expected of finders by Python's import system.
@@ -391,16 +396,16 @@ interface expected of finders by Python's import system.
0 commit comments