How to use pluginbase - 10 common examples

To help you get started, we’ve selected a few pluginbase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitsuhiko / pluginbase / tests / test_basics.py View on Github external
# A module can always find its own source as well (the hello module
    # calls get_plugin_source() itself).
    with source:
        from dummy.plugins import hello
    assert hello.get_plugin_source() is source

    # Last but not least the plugin source can be found by module names
    # (in a plugin source block by the import name and in any case by
    # the internal name)
    with source:
        assert get_plugin_source('dummy.plugins.hello') is source
    assert get_plugin_source(hello.__name__) is source

    # As well as by module object.
    assert get_plugin_source(hello) is source
github mitsuhiko / pluginbase / tests / test_basics.py View on Github external
# Inside a source block we can find the source through mere calling.
    with source:
        assert get_plugin_source() is source

    # A module can always find its own source as well (the hello module
    # calls get_plugin_source() itself).
    with source:
        from dummy.plugins import hello
    assert hello.get_plugin_source() is source

    # Last but not least the plugin source can be found by module names
    # (in a plugin source block by the import name and in any case by
    # the internal name)
    with source:
        assert get_plugin_source('dummy.plugins.hello') is source
    assert get_plugin_source(hello.__name__) is source

    # As well as by module object.
    assert get_plugin_source(hello) is source
github mitsuhiko / pluginbase / tests / test_basics.py View on Github external
# Inside a source block we can find the source through mere calling.
    with source:
        assert get_plugin_source() is source

    # A module can always find its own source as well (the hello module
    # calls get_plugin_source() itself).
    with source:
        from dummy.plugins import hello
    assert hello.get_plugin_source() is source

    # Last but not least the plugin source can be found by module names
    # (in a plugin source block by the import name and in any case by
    # the internal name)
    with source:
        assert get_plugin_source('dummy.plugins.hello') is source
    assert get_plugin_source(hello.__name__) is source

    # As well as by module object.
    assert get_plugin_source(hello) is source
github mitsuhiko / pluginbase / tests / test_basics.py View on Github external
def test_fetching_plugin_source(source):
    # Finding the plugin source outside of a plugin and without a with
    # block of a plugin source returns None.
    assert get_plugin_source() is None

    # Inside a source block we can find the source through mere calling.
    with source:
        assert get_plugin_source() is source

    # A module can always find its own source as well (the hello module
    # calls get_plugin_source() itself).
    with source:
        from dummy.plugins import hello
    assert hello.get_plugin_source() is source

    # Last but not least the plugin source can be found by module names
    # (in a plugin source block by the import name and in any case by
    # the internal name)
    with source:
        assert get_plugin_source('dummy.plugins.hello') is source
    assert get_plugin_source(hello.__name__) is source

    # As well as by module object.
    assert get_plugin_source(hello) is source
github BBVA / deeptracy / deeptracy / plugin_store.py View on Github external
def load_plugins(self):
        session = db.Session()
        deactivate_all_plugins(session)
        session.commit()

        default_paths = self.get_all_plugin_paths()

        # Load plugins from directories
        plugin_base = PluginBase(package="deeptracy.plugins")
        plugin_manager = plugin_base.make_plugin_source(searchpath=default_paths)

        # Locate plugins
        plugins_found = {}

        for module in plugin_manager.list_plugins():

            if module == 'store':
                continue

            module_objects = plugin_manager.load_plugin(module)

            for plugin_name, plugin_obj in vars(module_objects).items():
                if plugin_name.startswith("_") or type(plugin_obj).__name__ != "function":
                    continue
github mitsuhiko / pluginbase / pluginbase.py View on Github external
def _setup_base_package(module_name):
    try:
        mod = __import__(module_name, None, None, ['__name__'])
    except ImportError:
        mod = None
        if '.' in module_name:
            parent_mod = __import__(module_name.rsplit('.', 1)[0],
                                    None, None, ['__name__'])
        else:
            parent_mod = None

    if mod is None:
        mod = _IntentionallyEmptyModule(module_name)
        if parent_mod is not None:
            setattr(parent_mod, module_name.rsplit('.', 1)[-1], mod)
        sys.modules[module_name] = mod
github JakeMakesStuff / Cube / cube.py View on Github external
def load(self):

        self.discord_commands = dict()
        self.discord_callbacks = dict()
        self.plugins = dict()
        # Resets the dicts.

        self.plugin_base = PluginBase(package='__main__.plugins')
        # Defines the plugin base for Discord functions.

        self.plugin_source = self.plugin_base.make_plugin_source(
            searchpath=['./plugins'])
        # Defines the plugin source for Discord functions.

        listening_events = ["on_message", "on_ready", "on_message_delete", "on_reaction_add", "on_reaction_remove", "on_channel_delete", "on_channel_create",
        "on_channel_update", "on_member_join", "on_member_remove", "on_member_update", "on_server_join", "on_server_remove", "on_server_update"]
        # The list of events to look for and seperate.

        for plugin in self.plugin_source.list_plugins():
            self.plugins[plugin] = self.plugin_source.load_plugin(plugin)
            for i in self.plugins[plugin].__dict__.keys():
                if callable(self.plugins[plugin].__dict__[i]):
                    if i == "execute_on_init":
                        self.plugins[plugin].__dict__[i](self)
github mbr / unleash / unleash / plugin.py View on Github external
import os

from pluginbase import PluginBase
from logbook import Logger

from . import plugins
from .depgraph import DependencyGraph
from .exc import InvocationError

plugin_base = PluginBase(package='unleash.plugins')
log = Logger('plugins')


class PluginGraph(DependencyGraph):
    NAME_ATTR = 'PLUGIN_NAME'
    DEP_ATTR = 'PLUGIN_DEPENDS'

    def __init__(self, *args, **kwargs):
        super(PluginGraph, self).__init__(*args, **kwargs)
        self.plugin_mods = {}

    def add_plugin(self, plugin):
        name = getattr(plugin, self.NAME_ATTR)
        self.plugin_mods[name] = plugin

        self.add_obj(name, depends_on=getattr(plugin, self.DEP_ATTR, []))
github mozilla-iam / cis / cis / libs / validation.py View on Github external
def _initialize_plugin_source(self):
        plugin_base = PluginBase(package='cis.plugins.validation')
        plugin_source = plugin_base.make_plugin_source(
            searchpath=[
                os.path.join(
                    os.path.abspath(
                        os.path.dirname(__file__)
                    ),
                    '../plugins/validation/'
                )
            ]
        )

        return plugin_source
github milvus-io / milvus / shards / utils / pluginextension.py View on Github external
import importlib.util
from pluginbase import PluginBase, PluginSource


class MiPluginSource(PluginSource):
    def load_plugin(self, name):
        plugin = super().load_plugin(name)
        spec = importlib.util.spec_from_file_location(self.base.package + '.' + name, plugin.__file__)
        plugin = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(plugin)
        return plugin


class MiPluginBase(PluginBase):
    def make_plugin_source(self, *args, **kwargs):
        return MiPluginSource(self, *args, **kwargs)

pluginbase

PluginBase is a module for Python that enables the development of flexible plugin systems in Python.

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis

Similar packages