Skip to content

Commit 0112ab6

Browse files
committed
bpo-134740: Add missing documentation for importlib.metadata.distributions()
Add documentation for the distributions() function and DistributionFinder classes that were missing from the importlib.metadata documentation despite being part of the public API.
1 parent 3c05251 commit 0112ab6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Doc/library/importlib.metadata.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ Distributions
410410
Raises :exc:`PackageNotFoundError` if the named distribution
411411
package is not installed in the current Python environment.
412412

413+
.. function:: distributions(**kwargs)
414+
415+
Get all :class:`Distribution` instances in the current environment.
416+
417+
Any keyword arguments are passed to the ``find_distributions()`` method
418+
of the registered distribution finders (see :class:`DistributionFinder`).
419+
420+
Common keyword arguments include:
421+
422+
* ``name``: Filter to distributions matching this package name
423+
* ``path``: Search these path segments (defaults to :data:`sys.path`)
424+
425+
:return: An iterable of :class:`Distribution` instances.
426+
413427
.. class:: Distribution
414428

415429
Details of an installed distribution package.
@@ -418,6 +432,34 @@ Distributions
418432
equal, even if they relate to the same installed distribution and
419433
accordingly have the same attributes.
420434

435+
.. class:: DistributionFinder
436+
437+
An abstract base class subclass of :class:`importlib.abc.MetaPathFinder`
438+
capable of discovering installed distributions.
439+
440+
Custom providers should implement this interface to supply metadata
441+
for distributions that cannot be discovered through the file system
442+
or other built-in mechanisms.
443+
444+
See the section on :ref:`implementing-custom-providers` for more details.
445+
446+
.. class:: DistributionFinder.Context
447+
448+
Context object used to provide parameters when discovering distributions.
449+
450+
Keyword arguments supplied to :func:`distributions` or
451+
:meth:`Distribution.discover` are stored as attributes in the context
452+
object and can be used by distribution finders to filter or customize
453+
their search results.
454+
455+
The context provides these attributes:
456+
457+
* ``name``: A package name to match, or ``None`` to match all distributions
458+
* ``path``: A list of directories to search (defaults to :data:`sys.path`)
459+
460+
Custom distribution finders can accept other keyword parameters through
461+
this context.
462+
421463
While the module level API described above is the most common and convenient usage,
422464
you can get all of that information from the :class:`!Distribution` class.
423465
:class:`!Distribution` is an abstract object that represents the metadata for
@@ -467,6 +509,8 @@ This metadata finder search defaults to ``sys.path``, but varies slightly in how
467509
- ``importlib.metadata`` will incidentally honor :py:class:`pathlib.Path` objects on ``sys.path`` even though such values will be ignored for imports.
468510

469511

512+
.. _implementing-custom-providers:
513+
470514
Implementing Custom Providers
471515
=============================
472516

0 commit comments

Comments
 (0)