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
A simple method to create strong password.

A simple method to create strong password.

1 Jan 23, 2022
A PG3D API Made with Python

PG3D Python API A Pixel Gun 3D Python API (Public Ver) Features Count: 29 How To Use? import api as pbn Examples pbn.isBanned(192819483) - True pbn.f

Karim 2 Mar 24, 2022
SimilarWeb for Team ACT v.0.0.1

SimilarWeb for Team ACT v.0.0.1 This module has been built to provide a better environment specifically for Similarweb in Team ACT. This module itself

Sunkyeong Lee 0 Dec 29, 2021
Xbox-Flood is for flood anything

Intruduction Installation Usage Installing Python 3 Wiki Getting Started Creating a Key Intruduction Xbox-Flood is for flooding messages (invitations

kayake 4 Feb 18, 2022
Hook and simulate global keyboard events on Windows and Linux.

keyboard Take full control of your keyboard with this small Python library. Hook global events, register hotkeys, simulate key presses and much more.

BoppreH 3.2k Jan 01, 2023
The code for 2021 MGTV AI Challenge Anti Stealing Link, and the online result ranks 10th.

赛题介绍 芒果TV-第二届“马栏山杯”国际音视频算法大赛-防盗链 随着业务的发展,芒果的视频内容也深受网友的喜欢,不少视频网站和应用开始盗播芒果的视频内容,盗链网站不经过芒果TV的前端系统,跳过广告播放,且消耗大量的服务器、带宽资源,直接给公司带来了巨大的经济损失,因此防盗链在日常运营中显得尤为重要

tongji40 16 Jun 17, 2022
This program can calculate the Aerial Distance between two cities.

Aerial_Distance_Calculator This program can calculate the Aerial Distance between two cities. This repository include both Jupyter notebook and Python

InvisiblePro 1 Apr 08, 2022
Labspy06 With Python

Labspy06 Profil Nama : Nafal mumtaz fuadi Nim : 312110457 Kelas : T1.21.A.2 Latihan 1 Ubahlah kode dibawah ini menjadi fungsi menggunakan lambda impor

Mas Nafal 1 Dec 12, 2021
Security-related flags and options for C compilers

Getting the maximum of your C compiler, for security

135 Nov 11, 2022
A Curated Collection of Awesome Python Scripts

A Curated Collection of Awesome Python Scripts that will make you go wow. This repository will help you in getting those green squares. Hop in and enjoy the journey of open source. 🚀

Prathima Kadari 248 Dec 31, 2022
Interactivity Lab: Household Pulse Explorable

Interactivity Lab: Household Pulse Explorable Goal: Build an interactive application that incorporates fundamental Streamlit components to offer a cur

1 Feb 10, 2022
Este projeto se trata de uma análise de campanhas de marketing de uma empresa que vende acessórios para veículos.

Marketing Campaigns Este projeto se trata de uma análise de campanhas de marketing de uma empresa que vende acessórios para veículos. 1. Problema A em

Bibiana Prevedello 1 Jan 12, 2022
A place where one-off ideas/partial projects can live comfortably

A place to post ideas, partial projects, or anything else that doesn't necessarily warrant its own repo, from my mind to the web.

Carson Scott 2 Feb 25, 2022
Open source style Deep Dream project

DeepDream ⚠️ If you don't have a gpu with cuda, the style transfer execution time will be much longer Prerequisites Python =3.8.10 How to Install sud

Patrick martins de lima 7 May 17, 2022
TimeWizard - A script that generates every single Time Wizard EDOPRO lflist possible

EDOPRO F&L list generator This project is just a script that generates every sin

Diamond Dude 2 Sep 28, 2022
Google Foobar challenge solutions from my experience and other's on the web.

Google Foobar challenge Google Foobar challenge solutions from my experience and other's on the web. Note: Problems indicated with "Mine" are tested a

Islam Ayman 6 Jan 20, 2022
Pipenv-local-deps-repro - Reproduction of a local transitive dependency on pipenv

Reproduction of the pipenv bug with transitive local dependencies. Clone this re

Lucas Duailibe 2 Jan 11, 2022
A simple watcher for the XTZ/kUSD pool on Quipuswap

Kolibri Quipuswap Watcher This repo holds the source code for the QuipuBot bot deployed to the #quipuswap-updates channel in the Kolibri Discord Setup

Hover Labs 1 Nov 18, 2021
Python implementation of the Learning Time-Series Shapelets method, that learns a shapelet-based time-series classifier with gradient descent.

shaplets Python implementation of the Learning Time-Series Shapelets method by Josif Grabocka et al., that learns a shapelet-based time-series classif

Mohamed Haseeb 187 Dec 14, 2022
Irrigation Component V4 providing support for a custom card

Irrigation Component V4 This release sees the delivery of a custom card https://github.com/petergridge/irrigation_card to render the program options s

12 Oct 28, 2022