A simple but flexible plugin system for Python.

Overview

PluginBase

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

Step 1:

from pluginbase import PluginBase
plugin_base = PluginBase(package='yourapplication.plugins')

Step 2:

plugin_source = plugin_base.make_plugin_source(
    searchpath=['./path/to/plugins', './path/to/more/plugins'])

Step 3:

with plugin_source:
    from yourapplication.plugins import my_plugin
my_plugin.do_something_cool()

Or alternatively:

my_plugin = plugin_source.load_plugin('my_plugin')
my_plugin.do_something_cool()
Comments
  • PluginBase causes ImportError in PyYAML

    PluginBase causes ImportError in PyYAML

    PluginBase seems to break PyYAML, causing ImportErrors on import.
    I'm using the latest version of PyYAML (3.11) and PluginBase.
    Tested on OS X and Linux.

    Importing PluginBase first causes errors:

    Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pluginbase
    >>> import yaml
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/pluginbase.py", line 404, in plugin_import
        fromlist, level)
      File "/usr/local/lib/python2.7/dist-packages/yaml/__init__.py", line 2, in <module>
        from error import *
      File "/usr/local/lib/python2.7/dist-packages/pluginbase.py", line 404, in plugin_import
        fromlist, level)
    ImportError: No module named error
    

    Importing YAML first works fine:

    Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import yaml
    >>> import pluginbase
    
    bug 
    opened by cesarvandevelde 13
  • Error when exiting a program

    Error when exiting a program

    Exception ignored in: <bound method PluginSource.__del__ of <pluginbase.PluginSource object at 0x7f1a4e229be0>>
    Traceback (most recent call last):
      File "/usr/lib/python3.4/site-packages/pluginbase.py", line 247, in __del__
      File "/usr/lib/python3.4/site-packages/pluginbase.py", line 303, in cleanup
      File "/usr/lib/python3.4/site-packages/pluginbase.py", line 318, in __cleanup
    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
    
    bug 
    opened by garncarz 9
  • KeyError warning when sys.modules is empty as PluginSource.cleanup is called

    KeyError warning when sys.modules is empty as PluginSource.cleanup is called

    Not sure of the exact cause yet, but running the following source on python 3.4:

    from pluginbase import PluginBase
    a_base = PluginBase('some')
    a_source = a_base.make_plugin_source(searchpath=['.'])
    
    import asyncio
    
    @asyncio.coroutine
    def what():
        return
    

    results in the following warning being displayed:

    Exception ignored in: <bound method PluginSource.__del__ of <pluginbase.PluginSource object at 0x021F0AF0>>
    Traceback (most recent call last):
      File "d:\python34\lib\site-packages\pluginbase.py", line 247, in __del__
      File "d:\python34\lib\site-packages\pluginbase.py", line 303, in cleanup
      File "d:\python34\lib\site-packages\pluginbase.py", line 319, in __cleanup
    KeyError: ('pluginbase._internalspace._spf57aab93650650e4c1433e9cb9bd5a38',)
    

    Could potentially be fixed by adding a default None to the _sys.modules.pop() call causing the KeyError.

    bug 
    opened by htoothrot 6
  • Loading recursion depth

    Loading recursion depth

    Would it be possible to add a recursion depth for the search path?

    my_program.py
    plugins
        - plugin 1
            - foo.py
            - bar.py
        - plugin 2
            - foobar.py
    

    Currently I am scanning plugins with os.listdir, and searchpathing each. Having a recursion depth would be great.

    question 
    opened by Kamik423 4
  • conflict fix with random module

    conflict fix with random module

    Raises "AttributeError: 'module' object has no attribute 'choice'" on python2 (2.7.10) because module name (of random plugin) conflicts with python's random module.

    bug 
    opened by talhasch 4
  • pluginbase cause import error in pyvirtualdisplay: ImportError: No module named display

    pluginbase cause import error in pyvirtualdisplay: ImportError: No module named display

    from pyvirtualdisplay import Display
      File "/Users/dev/.virtualenvs/kraken-32/lib/python2.7/site-packages/pluginbase.py", line 404, in plugin_import
        fromlist, level)
      File "/Users/dev/.virtualenvs/kraken-32/lib/python2.7/site-packages/pyvirtualdisplay/__init__.py", line 1, in <module>
        from display import Display
      File "/Users/dev/.virtualenvs/kraken-32/lib/python2.7/site-packages/pluginbase.py", line 404, in plugin_import
        fromlist, level)
    ImportError: No module named display
    
    bug duplicate 
    opened by garywu 4
  • list_plugins method drops the modules with same name from different plugin directory

    list_plugins method drops the modules with same name from different plugin directory

    The modules with same names in different plugin directory won't be returned in list_plugins.

    Here is my case, I have a plugins directory structure like this,

    plugins
    ├── __init__.py
    ├── builtin
    │   ├── __init__.py
    │   ├── logger
    │   │   ├── __init__.py
    │       ├── setup.py
    │   │   └── logger.py
    ├── device
    │   ├── __init__.py
    │   ├── setup.py
    

    Expect

    The list_plugins returns all the module names including those with the same name and could be load_plugin correctly. ['logger', 'setup', 'setup']

    Actual

    The list_plugins returns all the unique names only and could be load_plugin correctly. ['logger', 'setup']

    Code

    plugin_base = PluginBase(package='app.plugins',
                                searchpath=[get_path('plugins/builtin')])
    
    source = plugin_base.make_plugin_source(
        searchpath=[get_path('./plugins/%s/' % name)],
        identifier=self.name)
    print source.list_plugins()
    
    opened by xingheng 3
  • DeprecationWarning in pluginbase.py line 439

    DeprecationWarning in pluginbase.py line 439

    c:\python\python37\lib\site-packages\pluginbase.py:439: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

    bug invalid 
    opened by awlosnie 2
  • get_searchpath function corrected for recursive directories retrieval

    get_searchpath function corrected for recursive directories retrieval

    get_searchpath method(in pluginbase.py) is not returning all the sub-directories in the given path.This fix gives the subdirectories as well. For example , for the below directory structure, the current code in get_searchpath is not returning all the sub-directories. app1

    • app2 -test2.py
    • test1.py app3 -app4
      • test4.py
    • test3.py

    It has been fixed in this commit.

    bug 
    opened by avinashraghuthu 2
  • list_plugins() displaying each plugin twice, but I'm probably mistaken about something

    list_plugins() displaying each plugin twice, but I'm probably mistaken about something

    $ tree -I 'venv|.git|__pycache__'
    .
    ├── app.py
    └── sources
        ├── one.py
        └── two.py
    
    from pluginbase import PluginBase
    
    plugin_base = PluginBase(package='app.sources')
    plugin_source = plugin_base.make_plugin_source(searchpath=['./sources'])
    
    for plugin_name in plugin_source.list_plugins():
        print(plugin_name)
    

    And when running app.py, I see:

    :!/usr/bin/env python app.py
    one
    two
    one
    two
    

    If you could kindly point out the error I'm most definitely making, that'd be cool.

    question 
    opened by shmup 2
  • importerror: util

    importerror: util

    when I have:

    from pluginbase import PluginBase
    from pyechonest import config
    from pyechonest import song
    

    I get

    Traceback (most recent call last):
      File "partyled.py", line 9, in <module>
        from pyechonest import song
      File "/usr/local/lib/python2.7/site-packages/pluginbase.py", line 404, in plugin_import
        fromlist, level)
      File "build/bdist.macosx-10.10-x86_64/egg/pyechonest/song.py", line 12, in <module>
      File "/usr/local/lib/python2.7/site-packages/pluginbase.py", line 404, in plugin_import
        fromlist, level)
    ImportError: No module named util
    

    however if I change the order to

    from pyechonest import config
    from pyechonest import song
    from pluginbase import PluginBase
    

    things work fine. Given the order in which things override, I'm inclined to suspect of PluginBase of doing something weird here.

    bug duplicate 
    opened by tacoe 2
Releases(1.0.0)
Owner
Armin Ronacher
Software developer and Open Source nut. Creator of the Flask framework. Engineering at @getsentry. Other things of interest: @pallets and @rust-lang
Armin Ronacher
Hasklig - a code font with monospaced ligatures

Hasklig – Ligatures for code Programming languages are limited to relatively few characters. As a result, combined character operators surfaced quite

Ian Tuomi 5.3k Jan 03, 2023
BridgeWalk is a partially-observed reinforcement learning environment with dynamics of varying stochasticity.

BridgeWalk is a partially-observed reinforcement learning environment with dynamics of varying stochasticity. The player needs to walk along a bridge to reach a goal location. When the player walks o

Danijar Hafner 6 Jun 13, 2022
laTEX is awesome but we are lazy -> groff with markdown syntax and inline code execution

pyGroff A wrapper for groff using python to have a nicer syntax for groff documents DOCUMENTATION Very similar to markdown. So if you know what that i

Subhaditya Mukherjee 27 Jul 23, 2022
Senior Comprehensive Project For Python

Senior Comprehensive Project Author: Grey Hutchinson My project, which I nicknamed “Murmur”, was to create a research tool that would use neural netwo

1 May 29, 2022
A tool for removing PUPs using signatures

Unwanted program removal tool A tool for removing PUPs using signatures What is the unwanted program removal tool? The unwanted program removal tool i

4 Sep 20, 2022
Gerador do Arquivo Magnético Sintegra em Python

pysintegra é uma lib simples com o objetivo de facilitar a geração do arquivo SINTEGRA seguindo o Convênio ICMS 57/95. Com o surgimento do SPED, muito

Felipe Correa 5 Apr 07, 2022
A partial-transpiler that converts a subset of Python to the Folders esoteric programming language

Py2Folders A partial-transpiler that converts a subset of Python to the Folders esoteric programming language Folders Folders is an esoteric programmi

Daniel Johnson 1 Dec 23, 2021
WGGCommute - Adding Commute Times to WG-Gesucht Listings

WGGCommute - Adding Commute Times to WG-Gesucht Listings This is a barebones implementation of a chrome extension that can be used to add commute time

Jannis 2 Jul 20, 2022
A minimalist production ready plugin system

pluggy - A minimalist production ready plugin system This is the core framework used by the pytest, tox, and devpi projects. Please read the docs to l

pytest-dev 876 Jan 05, 2023
Prototype application for GCM bias-correction and downscaling

dodola Prototype application for GCM bias-correction and downscaling This is an unstable prototype. This is under heavy development. Features Nothing!

Climate Impact Lab 9 Dec 27, 2022
combs is a package used to generate all possible combinations of a given length k on a given set.

The package combs is a package used to generate all possible combinations of a given length k on a given set. The set is given as a list, and k must b

1 Dec 24, 2021
MeerKAT radio telescope simulation package. Built to simulate multibeam antenna data.

MeerKATgen MeerKAT radio telescope simulation package. Designed with performance in mind and utilizes Just in time compile (JIT) and XLA backed vectro

Peter Ma 6 Jan 23, 2022
jonny is a stack based programming language

jonny-lang jonny is a stack based programming language also compiling jonny files currently doesnt work on windows you can probably compile jonny file

1 Nov 24, 2021
Organize seu linux - organize your linux

OrganizeLinux Organize seu linux - organize your linux Organize seu linux Uma forma rápida de separar arquivos dispersos em pastas. formatos a serem c

Marcus Vinícius Ribeiro Andrade 1 Nov 30, 2021
Service for working with open data of the State Duma of the Russian Federation

Сервис для работы с открытыми данными Госдумы РФ Исходные данные из API Госдумы РФ извлекаются с помощью Apache Nifi и приземляются в хранилище Clickh

Aleksandr Sergeenko 2 Feb 14, 2022
People tracker on the Internet: OSINT analysis and research tool by Jose Pino

trape (stable) v2.0 People tracker on the Internet: Learn to track the world, to avoid being traced. Trape is an OSINT analysis and research tool, whi

Jose Pino 7.3k Dec 30, 2022
JARVIS PC Assistant is an assisting program to make your computer easier to use

JARVIS-PC-Assistant JARVIS PC Assistant is an assisting program to make your computer easier to use Welcome to the J.A.R.V.I.S. PC Assistant help file

Dasun Nethsara 2 Dec 02, 2022
Data and analysis relating to the 5.8M Melbourne quake of 2021

quake2021 Data and analysis relating to the 5.8M Melbourne quake of 2021 Monash University Woodside Living Lab Building The building is located here T

Colin Caprani 6 May 16, 2022
CupScript is a simple programing language made with python

CupScript CupScript is a simple programming language made with python It includes some basic functions, variables, loops, and some other built in func

FUSEN 23 Dec 29, 2022
🙌Kart of 210+ projects based on machine learning, deep learning, computer vision, natural language processing and all. Show your support by ✨ this repository.

ML-ProjectKart 📌 Repository This kart showcases the finest collection of all projects based on machine learning, deep learning, computer vision, natu

Prathima Kadari 203 Dec 28, 2022