Api Reference¶
-
class
pluggy.
PluginManager
(project_name, implprefix=None)[source]¶ Bases:
object
Core Pluginmanager class which manages registration of plugin objects and 1:N hook calling.
You can register new hooks by calling
add_hookspec(module_or_class)
. You can register plugin objects (which contain hooks) by callingregister(plugin)
. The Pluginmanager is initialized with a prefix that is searched for in the names of the dict of registered plugin objects.For debugging purposes you can call
enable_tracing()
which will subsequently send debug information to the trace helper.-
add_hookcall_monitoring
(before, after)[source]¶ add before/after tracing functions for all hooks and return an undo function which, when called, will remove the added tracers.
before(hook_name, hook_impls, kwargs)
will be called ahead of all hook calls and receive a hookcaller instance, a list of HookImpl instances and the keyword arguments for the hook call.after(outcome, hook_name, hook_impls, kwargs)
receives the same arguments asbefore
but also a_Result`
object which represents the result of the overall hook call.
-
add_hookspecs
(module_or_class)[source]¶ add new hook specifications defined in the given module_or_class. Functions are recognized if they have been decorated accordingly.
-
check_pending
()[source]¶ Verify that all hooks which have not been verified against a hook specification are optional, otherwise raise PluginValidationError
-
get_canonical_name
(plugin)[source]¶ Return canonical name for a plugin object. Note that a plugin may be registered under a different name which was specified by the caller of register(plugin, name). To obtain the name of an registered plugin use
get_name(plugin)
instead.
-
list_plugin_distinfo
()[source]¶ return list of distinfo/plugin tuples for all setuptools registered plugins.
-
load_setuptools_entrypoints
(entrypoint_name)[source]¶ Load modules from querying the specified setuptools entrypoint name. Return the number of loaded plugins.
-
register
(plugin, name=None)[source]¶ Register a plugin and return its canonical name or None if the name is blocked from registering. Raise a ValueError if the plugin is already registered.
-
-
exception
pluggy.
PluginValidationError
(plugin, message)[source]¶ Bases:
exceptions.Exception
plugin failed validation.
Parameters: plugin (object) – the plugin which failed validation, may be a module or an arbitrary object.
-
class
pluggy.
HookspecMarker
(project_name)[source]¶ Bases:
object
Decorator helper class for marking functions as hook specifications.
You can instantiate it with a project_name to get a decorator. Calling PluginManager.add_hookspecs later will discover all marked functions if the PluginManager uses the same project_name.
-
class
pluggy.
HookimplMarker
(project_name)[source]¶ Bases:
object
Decorator helper class for marking functions as hook implementations.
You can instantiate with a project_name to get a decorator. Calling PluginManager.register later will discover all marked functions if the PluginManager uses the same project_name.
-
_Result.
get_result
()[source]¶ Get the result(s) for this hook call.
If the hook was marked as a
firstresult
only a single value will be returned otherwise a list of results.