Plugin Management¶
FlaskBB provides a couple of helpers for helping with plugin management.
Plugin Registry¶
The plugin registry holds all available plugins. It shows the plugin’s status whether it is enabled or disabled, installable or installed. The registry also holds a reference to the plugin’s instance, provides an interface to access the plugins metadata and stores its settings.
You can query it like any SQLAlchemy Model:
plugin = PluginRegistry.query.filter_by(name="portal").first()
-
class
flaskbb.plugins.models.
PluginRegistry
(**kwargs)[source]¶ -
settings
¶ Returns a dict with contains all the settings in a plugin.
-
info
¶ Returns some information about the plugin.
-
is_installable
¶ Returns True if the plugin has settings that can be installed.
-
is_installed
¶ Returns True if the plugin is installed.
-
Plugin Manager¶
FlaskBB overrides the PluginManager from pluggy to provide some additional functionality like accessing the information stored in a setup.py file. The plugin manager will only list the currently enabled plugins and can be used to directly access the plugins instance by its name.
Accessing a plugins instance is as easy as:
plugin_instance = current_app.pluggy.get_plugin(name)
-
class
flaskbb.plugins.manager.
FlaskBBPluginManager
(project_name)[source]¶ Overwrites
pluggy.PluginManager
to add FlaskBB specific stuff.-
register
(plugin, name=None, internal=False)[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.
-
unregister
(plugin=None, name=None)[source]¶ Unregister a plugin object and all its contained hook implementations from internal data structures.
-
load_setuptools_entrypoints
(entrypoint_name)[source]¶ Load modules from querying the specified setuptools entrypoint name. Return the number of loaded plugins.
-
add_hookcall_monitoring
(before, after)¶ 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)¶ add new hook specifications defined in the given
module_or_class
. Functions are recognized if they have been decorated accordingly.
-
check_pending
()¶ Verify that all hooks which have not been verified against a hook specification are optional, otherwise raise
PluginValidationError
.
-
enable_tracing
()¶ enable tracing of hook calls and return an undo function.
-
get_canonical_name
(plugin)¶ 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.
-
get_hookcallers
(plugin)¶ get all hook callers for the specified plugin.
-
get_plugins
()¶ return the set of registered plugins.
-
has_plugin
(name)¶ Return
True
if a plugin with the given name is registered.
-
is_registered
(plugin)¶ Return
True
if the plugin is already registered.
-
list_name_plugin
()¶ return list of name/plugin pairs.
-
list_plugin_distinfo
()¶ return list of distinfo/plugin tuples for all setuptools registered plugins.
-
subset_hook_caller
(name, remove_plugins)¶ Return a new
_hooks._HookCaller
instance for the named method which manages calls to all registered plugins except the ones from remove_plugins.
-