2929
3030
3131if TYPE_CHECKING :
32- # importtlib.metadata import is slow, defer it.
3332 import importlib .metadata
3433
34+ from ._compat import DistFacade
35+
3536
3637_BeforeTrace : TypeAlias = Callable [[str , Sequence [HookImpl ], Mapping [str , Any ]], None ]
3738_AfterTrace : TypeAlias = Callable [
@@ -62,24 +63,6 @@ def __init__(self, plugin: _Plugin, message: str) -> None:
6263 self .plugin = plugin
6364
6465
65- class DistFacade :
66- """Emulate a pkg_resources Distribution"""
67-
68- def __init__ (self , dist : importlib .metadata .Distribution ) -> None :
69- self ._dist = dist
70-
71- @property
72- def project_name (self ) -> str :
73- name : str = self .metadata ["name" ]
74- return name
75-
76- def __getattr__ (self , attr : str , default : Any | None = None ) -> Any :
77- return getattr (self ._dist , attr , default )
78-
79- def __dir__ (self ) -> list [str ]:
80- return sorted (dir (self ._dist ) + ["_dist" , "project_name" ])
81-
82-
8366class PluginManager :
8467 """Core class which manages registration of plugin objects and 1:N hook
8568 calling.
@@ -101,7 +84,9 @@ def __init__(self, project_name: str) -> None:
10184 #: The project name.
10285 self .project_name : Final = project_name
10386 self ._name2plugin : Final [dict [str , _Plugin ]] = {}
104- self ._plugin_distinfo : Final [list [tuple [_Plugin , DistFacade ]]] = []
87+ self ._plugin_distinfo : Final [
88+ list [tuple [_Plugin , importlib .metadata .Distribution ]]
89+ ] = []
10590 #: The "hook relay", used to call a hook on all registered plugins.
10691 #: See :ref:`calling`.
10792 self .hook : Final = HookRelay ()
@@ -418,13 +403,33 @@ def load_setuptools_entrypoints(self, group: str, name: str | None = None) -> in
418403 continue
419404 plugin = ep .load ()
420405 self .register (plugin , name = ep .name )
421- self ._plugin_distinfo .append ((plugin , DistFacade ( dist ) ))
406+ self ._plugin_distinfo .append ((plugin , dist ))
422407 count += 1
423408 return count
424409
425410 def list_plugin_distinfo (self ) -> list [tuple [_Plugin , DistFacade ]]:
426411 """Return a list of (plugin, distinfo) pairs for all
427- setuptools-registered plugins."""
412+ setuptools-registered plugins.
413+
414+ .. note::
415+ The distinfo objects are wrapped with :class:`~pluggy._compat.DistFacade`
416+ for backward compatibility with the legacy pkg_resources API.
417+ Use the modern :meth:`list_plugin_distributions` method to get
418+ unwrapped :class:`importlib.metadata.Distribution` objects.
419+ """
420+
421+ from ._compat import DistFacade
422+
423+ return [(plugin , DistFacade (dist )) for plugin , dist in self ._plugin_distinfo ]
424+
425+ def list_plugin_distributions (
426+ self ,
427+ ) -> list [tuple [_Plugin , importlib .metadata .Distribution ]]:
428+ """Return a list of (plugin, distribution) pairs for all plugins
429+ loaded via entry points.
430+
431+ .. versionadded:: 1.7
432+ """
428433 return list (self ._plugin_distinfo )
429434
430435 def list_name_plugin (self ) -> list [tuple [str , _Plugin ]]:
0 commit comments