Skip to main content

Python Plugin Management, simplified

Project description

Build Status Coverage Status Code Climate

python plugin management, simplified.

Repo: https://github.com/benhoff/pluginmanager

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 or register your custom class with IPlugin

import pluginmanager

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

Register your class as subclass of IPlugin.

import pluginmanager

pluginmanager.IPlugin.register(YourClassHere)

Add Plugins Manually

import pluginmanager

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

plugins = plugin_interface.get_instances()

pluginmanager is defaulted to automatically instantiate UNIQUE classes. The automatic instantiation and uniqueness constraint can be changed.

Alternatively, add instances. Note that the uniqueness behavior is still enforced for instances.

import pluginmanager

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

plugins = plugin_interface.get_instances()

Filter Instances

Not interested in getting every instance? You can pass in a class to get back just 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)

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

Interfaces

Interfaces were 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, which is designed to be as stateless as possible, and have interjectable options, where applicable.

PluginInterface provides the cability to instantiate two other interfaces, the BlacklistInterface and FilterInterface. These interfaces provide universal access to the blacklisting (selectively implemented) and filtering APIs respectively.

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.

NOTE: Final implementation of filters and how they interact with the library is currently a WIP and should be considered unstable.

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.1.3.tar.gz (17.6 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.1.3-py2.py3-none-any.whl (71.9 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for pluginmanager-0.1.3.tar.gz
Algorithm Hash digest
SHA256 17551a65588cefc3ece0a4acd4b50dffb41409a49e7173eec4322b5820ca3e82
MD5 cf40c892b7b9cf0f76a94a44728ce40e
BLAKE2b-256 f72b6f9f527b384007ab700836f67ebc1846b2f5bad6758a1150f47591088dbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pluginmanager-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ec510126f533e2f10150272f81bb429e8f6c1d12500a7aebda2b73fccfa340ee
MD5 e5a6b97796c2f84e0d917eec149627d2
BLAKE2b-256 7216d00bf04decae5fb0f0d0add78db5e0eb61a5e0a1639c0658e32a73465207

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