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
Launcher program to select which version of the Q-Sys software to launch.

QSC-QSYS Launcher Launcher program to select which version of the Q-Sys software to launch. Instructions To use the application simply save the "Q-Sys

Zach Lisko 2 Sep 28, 2022
A custom advent of code I am completing

advent-of-code-custom A custom advent of code I am doing in python. The link to the problems I am solving is here: https://github.com/seldoncode/Adven

Rocio PV 2 Dec 11, 2021
Herramienta para poder automatizar reuniones en Zoom.

Crear Reunión Zoom con Python Herramienta para poder automatizar reuniones en Zoom. Librerías Requeridas Nombre Comando PyAutoGui pip install pyautogu

JkDev 3 Nov 12, 2022
【幼盾】个性化图片徽章服务!

【幼盾】个性化图片徽章服务! 你对方形的徽章感到无聊了吗?想要定制属于自己的开源项目徽章了吗? 快来使用unv-shield吧! unv-shield提供包含自定义图片的徽章服务,可以让你的项目主页更加个性化!

黄巍 130 Dec 23, 2022
The most hackable keyboard in all the land

MiRage Modular Keyboard © 2021 Zack Freedman of Voidstar Lab Licensed Creative Commons 4.0 Attribution Noncommercial Share-Alike The MiRage is a 60% o

Zack Freedman 558 Dec 30, 2022
NASH 2021 project... this may or may not end up working 🤷‍♂️

wavespace synthesiser this is my NASH 2021 project, which may or may not end up working 🤷‍♂️ what is going on? imagine you have a big folder of audio

Ben Hayes 12 May 17, 2022
Box CRUD API With Python

Box CRUD API: Consider a store which has an inventory of boxes which are all cuboid(which have length breadth and height). Each Cuboid has been added

Akhil Bhalerao 3 Feb 17, 2022
This Program Automates The Procces Of Adding Camos On Guns And Saving Them On Modern Warfare Guns

This Program Automates The Procces Of Adding Camos On Guns And Saving Them On Modern Warfare Guns

Flex Tools 6 May 26, 2022
Ramadhan countdown - Simple daily reminder about upcoming Ramadhan

Ramadhan Countdown Bot Simple bot for displaying daily reminder about Islamic pr

Abdurrahman Shofy Adianto 1 Feb 06, 2022
A10 cipher - A Hill 2x2 cipher that totally gone wrong

A10_cipher This is a Hill 2x2 cipher that totally gone wrong, it encrypts with H

Caner Çetin 15 Oct 19, 2022
samples of neat code

NEAT-samples Some samples of code and config files for use with the NEAT-Python package These samples are largely copy and pasted, so if you

Harrison 50 Sep 28, 2022
Do you need a screensaver for CircuitPython? Of course you do

circuitpython_screensaver Do you need a screensaver for CircuitPython? Of course you do Demo video of dvdlogo screensaver: screensaver_dvdlogo.mp4 Dem

Tod E. Kurt 8 Sep 02, 2021
A fishing bot script written in Python!

A fishing bot script written in Python!

Anel Drocic 3 Nov 03, 2021
Digdata presented 'BrandX' as a clothing brand that wants to know the best places to set up a 'pop up' store.

Digdata presented 'BrandX' as a clothing brand that wants to know the best places to set up a 'pop up' store. I used the dataset given to write a program that ranks these places.

Mahmoud 1 Dec 11, 2021
Problem 5: Fermat near-misses

Problem 5: Fermat near-misses fermatnearmiss This is a script that computes fermat nearm misses when the -f option is set and requires users to input

CHRIS BYRON (Int0x80) 1 Jan 08, 2022
Companion Web site for Fluent Python, Second Edition

Fluent Python, the site Source code and content for fluentpython.com. The site complements Fluent Python, Second Edition with extra content that did n

Fluent Python 49 Dec 08, 2022
A Puzzle A Day Keep the Work Away

A Puzzle A Day Keep the Work Away No moyu again!

P4SSER8Y 5 Feb 12, 2022
LOL英雄联盟云顶之弈挂机刷代币脚本,全自动操作,智能逻辑,功能齐全。

LOL云顶之弈挂机刷代币脚本 这是2019年全球总决赛写的一个云顶挂机脚本,python完成的。 功能: 自动拿牌卖牌 策略是高星策略,非固定阵容 自动登陆账号、打码、异常重启 战利品截图上传百度云 web中控发号,改密码,查看信息等 代码是三天赶出来的,所以有点混乱,WEB中控代码也不知道扔哪去了

77 Oct 10, 2022
Tool that adds githuh profile views to ur acc

Tool that adds githuh profile views to ur acc

Lamp 2 Nov 28, 2021
Packaging tools for shanty services.

parcel Packaging tools for shanty services. What? Services are docker containers deployed by shanty on a hosting appliance. Each service consists of t

0 Jan 20, 2022