@@ -410,6 +410,20 @@ Distributions
410
410
Raises :exc: `PackageNotFoundError ` if the named distribution
411
411
package is not installed in the current Python environment.
412
412
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
+
413
427
.. class :: Distribution
414
428
415
429
Details of an installed distribution package.
@@ -418,6 +432,34 @@ Distributions
418
432
equal, even if they relate to the same installed distribution and
419
433
accordingly have the same attributes.
420
434
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
+
421
463
While the module level API described above is the most common and convenient usage,
422
464
you can get all of that information from the :class: `!Distribution ` class.
423
465
: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
467
509
- ``importlib.metadata `` will incidentally honor :py:class: `pathlib.Path ` objects on ``sys.path `` even though such values will be ignored for imports.
468
510
469
511
512
+ .. _implementing-custom-providers :
513
+
470
514
Implementing Custom Providers
471
515
=============================
472
516
0 commit comments