Skip to main content

Python Plugin Management, simplified

Project description

Build Status Coverage Status Code Climate

python plugin management, simplified.

Documentation

Source Code

Library under development. Contains rough edges/unfinished functionality. API subject to changes.

Installation

pip install pluginmanager

-or-

pip install git+https://github.com/benhoff/pluginmanager.git

Quickstart

from pluginmanager import PluginInterface

plugin_interface = PluginInterface()
plugin_interface.set_plugin_directories('my/fancy/plugin/path')
plugin_interface.collect_plugins()

plugins = plugin_interface.get_instances()

Custom Plugins

The quickstart will only work if you subclass IPlugin for your custom plugins.

import pluginmanager

class MyCustomPlugin(pluginmanager.IPlugin):
    def __init__(self):
        self.name = 'custom_name'
        super().__init__()

Or register your class as subclass of IPlugin.

import pluginmanager

pluginmanager.IPlugin.register(YourClassHere)

Add Plugins Manually

Add classes.

import pluginmanager

plugin_interface = pluginmanager.PluginInterface()
plugin_interface.add_plugins(YourCustomClassHere)

plugins = plugin_interface.get_instances()

Alternatively, add instances.

import pluginmanager

plugin_interface = pluginmanager.PluginInterface()
plugin_interface.add_plugins(your_instance_here)

plugins = plugin_interface.get_instances()

pluginmanager is defaulted to automatically instantiate unique instances.

Disable automatic instantiation.

import pluginmanager

plugin_interface = pluginmanager.PluginInterface()
plugin_manager = plugin_interface.plugin_manager

plugin_manager.instantiate_classes = False

Disable uniquness (Only one instance of class per pluginmanager)

import pluginmanager

plugin_interface = pluginmanager.PluginInterface()
plugin_manager = plugin_interface.plugin_manager

plugin_manager.unique_instances = False

Filter Instances

Pass in a class to get back just the instances of a class

import pluginmanager

plugin_interface = pluginmanager.PluginInterface()
plugin_interface.set_plugin_directories('my/fancy/plugin/path')
plugin_interface.collect_plugins()

all_instances_of_class = plugin_interface.get_instances(MyPluginClass)

Alternatively, create and pass in your own custom filters.

def custom_filter(plugins):
    result = []
    for plugin in plugins:
        if plugin.name == 'interesting name':
            result.append(plugin)
    return result

filtered_plugins = plugin_interface.get_instances(custom_filter)

class FilterWithState(object):
    def __init__(self, name):
        self.stored_name = name

    def __call__(self, plugins):
        result = []
        for plugin in plugins:
            if plugin.name == self.stored_name:
                result.append(plugin)
        return result

Architecture

pluginmanager was designed to be as extensible as possible while also being easy to use. There are three layers of access.

Interfaces:

public facing

Managers:

extended or replaced

Filters:

implementation specific

Interface

An interface was used to provide a simple programmer interface while maintaining the ability to separate out the concerns of the implementation. The main interface is the PluginInterface. PluginInterface is designed to be as stateless as possible, and have interjectable options where applicable.

Managers

There are four managers which make up the core of the library.

DirectoryManager:

Maintains directory state. Responsbile for recursively searching through directories

FileManager:

Can maintain filepath state. Does maintain file filter state. Responsible for applying file filters to filepaths passed gotten from directories

ModuleManager:

Loads modules from source code. Keeps track of loaded modules. Maintains module filter state. Responsible for applying module filters to modules to get out plugins.

PluginManager:

Instantiates plugins. Maintains plugin state.

Filters

Filters are designed to offer implementation-level extensiblity. Want to only return only files start with “plugin”? Create a filter for it. Or use some of the provided filters to provide the desired implementation.

All filters are callable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pluginmanager-0.2.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pluginmanager-0.2.0-py2.py3-none-any.whl (40.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pluginmanager-0.2.0.tar.gz.

File metadata

  • Download URL: pluginmanager-0.2.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pluginmanager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9a1b95d3e0deb4800f171742db56b97cca2d246bb8e748295ebff3d5e3535768
MD5 96dbe5fba26e48e14a1126c3f39ef056
BLAKE2b-256 35be6309b42e38c28f5f93ba83277b13774f4745adafaf36fb515dcc4d629a77

See more details on using hashes here.

File details

Details for the file pluginmanager-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pluginmanager-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0d69b7c91b124e9bd6c0e3a22fe6a5a5a5a77870b8bae25eb37b198f17228a00
MD5 9192946e3e05db2eac3daa4e7da93b7b
BLAKE2b-256 1aaf6f5806e3fb6d566a8bbd6ea86e9a002a5b2b7501c6e8d18d29acaa100991

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page