Api Reference¶
-
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. CallingPluginManager.register()
later will discover all marked functions if thePluginManager
uses the same project_name.
-
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 thePluginManager
uses the same project_name.
-
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_hookspecs(module_or_class)
. You can register plugin objects (which contain hooks) by callingregister(plugin)
. ThePluginManager
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
PluginManager.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 apluggy.callers._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 useget_name(plugin)
instead.
-
list_plugin_distinfo
()[source]¶ return list of distinfo/plugin tuples for all setuptools registered plugins.
-
load_setuptools_entrypoints
(group, name=None)[source]¶ Load modules from querying the specified setuptools
group
.- Parameters
group (str) – entry point group to load plugins
name (str) – if given, loads only plugins with the given
name
.
- Return type
int
- Returns
return the number of loaded plugins by this call.
-
register
(plugin, name=None)[source]¶ Register a plugin and return its canonical name or
None
if the name is blocked from registering. Raise aValueError
if the plugin is already registered.
-
subset_hook_caller
(name, remove_plugins)[source]¶ Return a new
hooks._HookCaller
instance for the named method which manages calls to all registered plugins except the ones from remove_plugins.
-
-
exception
pluggy.
PluginValidationError
(plugin, message)[source]¶ Bases:
Exception
plugin failed validation.
- Parameters
plugin (object) – the plugin which failed validation, may be a module or an arbitrary object.
-
_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.
-
_Result.
force_result
(result)[source]¶ Force the result(s) to
result
.If the hook was marked as a
firstresult
a single value should be set otherwise set a (modified) list of results. Any exceptions found during invocation will be deleted.
-
class
pluggy.hooks.
_HookCaller
(name, hook_execute, specmodule_or_class=None, spec_opts=None)[source]¶
-
_HookCaller.
call_extra
(methods, kwargs)[source]¶ Call the hook with some additional temporarily participating methods using the specified
kwargs
as call parameters.
-
_HookCaller.
call_historic
(result_callback=None, kwargs=None, proc=None)[source]¶ Call the hook with given
kwargs
for all registered plugins and for all plugins which will be registered afterwards.If
result_callback
is notNone
it will be called for for each non-None
result obtained from a hook implementation.Note
The
proc
argument is now deprecated.