plainbox.impl.secure.plugins – interface for accessing extension points

This module contains plugin interface for plainbox. Plugins are based on pkg_resources entry points feature. Any python package can advertise the existence of entry points associated with a given namespace. Any other package can query a given namespace and enumerate a sequence of entry points.

Each entry point has a name and importable identifier. The identifier can be imported using the load() method. A loaded entry point is exposed as an instance of PlugIn. A high-level collection of plugins (that may eventually also query alternate backends) is offered by PlugInCollection.

Using PlugInCollection.load() one can load all plugins from a particular namespace and work with them using provided utility methods such as PlugInCollection.get_by_name() or PlugInCollection.get_all_names()

The set of loaded plugins can be overridden by mock/patching PlugInCollection._get_entry_points(). This is especially useful for testing in isolation from whatever entry points may exist in the system.

class plainbox.impl.secure.plugins.FsPlugInCollection(path, ext, load=False, wrapper=<class 'plainbox.impl.secure.plugins.PlugIn'>)[source]

Collection of plug-ins based on filesystem entries

Instantiate with path and ext, call load() and then access any of the loaded plug-ins using the API offered. All loaded plugin information files are wrapped by a plug-in container. By default that is PlugIn but it may be adjusted if required.

The name of each plugin is the base name of the plugin file, the object of each plugin is the text read from the plugin file.

load()[source]

Load all plug-ins.

This method loads all plug-ins from the search directories (as defined by the path attribute). Missing directories are silently ignored.

class plainbox.impl.secure.plugins.IPlugIn[source]

Piece of code loaded at runtime, one of many for a given extension point

plugin_name[source]

name of the plugin, may not be unique

plugin_object[source]

external object

class plainbox.impl.secure.plugins.IPlugInCollection[source]

A collection of IPlugIn objects.

fake_plugins(plugins)[source]

Context manager for using fake list of plugins

Parameters:plugins – list of PlugIn-alike objects

The provided list of plugins overrides any previously loaded plugins and prevent loading any other, real, plugins. After the context manager exits the previous state is restored.

get_all_items()[source]

Get an iterator to a sequence of (name, plug-in)

get_all_names()[source]

Get an iterator to a sequence of plug-in names

get_all_plugins()[source]

Get an iterator to a sequence plug-ins

get_by_name(name)[source]

Get the specified plug-in (by name)

load()[source]

Load all plug-ins.

This method loads all plug-ins from the specified name-space. It may perform a lot of IO so it’s somewhat slow / expensive on a cold disk cache.

class plainbox.impl.secure.plugins.PkgResourcesPlugInCollection(namespace, load=False, wrapper=<class 'plainbox.impl.secure.plugins.PlugIn'>)[source]

Collection of plug-ins based on pkg_resources

Instantiate with namespace, call load() and then access any of the loaded plug-ins using the API offered. All loaded objects are wrapped by a plug-in container. By default that is PlugIn but it may be adjusted if required.

load()[source]

Load all plug-ins.

This method loads all plug-ins from the specified name-space. It may perform a lot of IO so it’s somewhat slow / expensive on a cold disk cache.

Note

this method queries pkg-resources only once.

class plainbox.impl.secure.plugins.PlugIn(name, obj)[source]

Simple plug-in that does not offer any guarantees beyond knowing it’s name and some arbitrary external object.

plugin_name[source]
plugin_object[source]
class plainbox.impl.secure.plugins.PlugInCollectionBase(load=False, wrapper=<class 'plainbox.impl.secure.plugins.PlugIn'>)[source]

Base class that shares some of the implementation with the other PlugInCollection implemenetations.

fake_plugins(plugins)[source]

Context manager for using fake list of plugins

Parameters:plugins – list of PlugIn-alike objects

The provided list of plugins overrides any previously loaded plugins and prevent loading any other, real, plugins. After the context manager exits the previous state is restored.

get_all_items()[source]

Get an iterator to a sequence of (name, plug-in)

get_all_names()[source]

Get an iterator to a sequence of plug-in names

get_all_plugins()[source]

Get an iterator to a sequence plug-ins

get_by_name(name)[source]

Get the specified plug-in (by name)

Previous topic

plainbox.impl.secure.launcher1 – plainbox-trusted-launcher-1

Next topic

plainbox.impl.secure.providers – providers package

This Page