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
While the above API is the most common and convenient usage, you can get all
273
320
of that information from the ``Distribution`` class. A ``Distribution`` is an
274
-
abstract object that represents the metadata for a Python package. You can
321
+
abstract object that represents the metadata for
322
+
a Python `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_. You can
275
323
get the ``Distribution`` instance::
276
324
277
325
>>> from importlib.metadata import distribution # doctest: +SKIP
@@ -291,22 +339,36 @@ instance::
291
339
>>> dist.metadata['License'] # doctest: +SKIP
292
340
'MIT'
293
341
294
-
The full set of available metadata is not described here. See :pep:`566`
295
-
for additional details.
342
+
The full set of available metadata is not described here.
343
+
See the `Core metadata specifications <https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata>`_ for additional details.
344
+
345
+
346
+
Distribution Discovery
347
+
======================
348
+
349
+
By default, this package provides built-in support for discovery of metadata
350
+
for file system and zip file `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_\s.
351
+
This metadata finder search defaults to ``sys.path``, but varies slightly in how it interprets those values from how other import machinery does. In particular:
352
+
353
+
- ``importlib.metadata`` does not honor :class:`bytes` objects on ``sys.path``.
354
+
- ``importlib.metadata`` will incidentally honor :py:class:`pathlib.Path` objects on ``sys.path`` even though such values will be ignored for imports.
296
355
297
356
298
357
Extending the search algorithm
299
358
==============================
300
359
301
-
Because package metadata is not available through :data:`sys.path` searches, or
302
-
package loaders directly, the metadata for a package is found through import
303
-
system :ref:`finders <finders-and-loaders>`. To find a distribution package's metadata,
360
+
Because `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_ metadata
361
+
is not available through :data:`sys.path` searches, or
362
+
package loaders directly,
363
+
the metadata for a distribution is found through import
364
+
system `finders`_. To find a distribution package's metadata,
304
365
``importlib.metadata`` queries the list of :term:`meta path finders <meta path finder>` on
305
366
:data:`sys.meta_path`.
306
367
307
-
The default ``PathFinder`` for Python includes a hook that calls into
308
-
``importlib.metadata.MetadataPathFinder`` for finding distributions
309
-
loaded from typical file-system-based paths.
368
+
By default ``importlib_metadata`` installs a finder for distribution packages
369
+
found on the file system.
370
+
This finder doesn't actually find any *distributions*,
371
+
but it can find their metadata.
310
372
311
373
The abstract class :py:class:`importlib.abc.MetaPathFinder` defines the
312
374
interface expected of finders by Python's import system.
@@ -335,4 +397,4 @@ a custom finder, return instances of this derived ``Distribution`` in the
335
397
336
398
.. _`entry point API`: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
0 commit comments