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.

get_settings_form()[source]

Generates a settings form based on the settings.

update_settings(settings)[source]

Updates the given settings of the plugin.

Parameters:settings – A dictionary containing setting items.
add_settings(settings, force=False)[source]

Adds the given settings to the plugin.

Parameters:
  • settings – A dictionary containing setting items.
  • force – Forcefully overwrite existing settings.

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.

set_blocked(name)[source]

Block registrations of the given name, unregister if already registered.

is_blocked(name)[source]

Return True if the name blockss registering plugins of that name.

get_plugin(name)[source]

Return a plugin or None for the given name.

get_name(plugin)[source]

Return name for registered plugin or None if not registered.

load_setuptools_entrypoints(entrypoint_name)[source]

Load modules from querying the specified setuptools entrypoint name. Return the number of loaded plugins.

get_metadata(name)[source]

Returns the metadata for a given name.

list_name()[source]

Returns only the enabled plugin names.

list_internal_name_plugin()[source]

Returns a list of internal name/plugin pairs.

list_plugin_metadata()[source]

Returns the metadata for all plugins

list_disabled_plugins()[source]

Returns a name/distinfo tuple pairs of disabled plugins.

get_disabled_plugins()[source]

Returns a list with disabled plugins.

get_internal_plugins()[source]

Returns a set of registered internal plugins.

get_external_plugins()[source]

Returns a set of registered external 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 as before but also a pluggy._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 use get_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.