473,320 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Plugin system

Hello,

another philosophical question:

How would you implement a plugin system (for a web-based application)?

Conditions are:
- One plugin can have one or many "parts" (or "subplugins", or whatever)
- Each subplugin has a type
- The rest of the plugin interface is dependent on the type

I have one possible solution in mind, but I want to wait for your
opinion before revealing it.

Reinhold

--
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel. -- Florian Diesch in dcoulm
Jul 18 '05 #1
7 1794
Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?


This is so general a question that I cannot think of anything concrete to answer.
Please ask again, with more detail about what you want/need/have in mind.

--Irmen
Jul 18 '05 #2
Irmen de Jong wrote:
Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?


This is so general a question that I cannot think of anything concrete to answer.
Please ask again, with more detail about what you want/need/have in mind.


Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.

Reinhold

--
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel. -- Florian Diesch in dcoulm
Jul 18 '05 #3
Reinhold Birkenfeld wrote:
Irmen de Jong wrote:
Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?


This is so general a question that I cannot think of anything concrete to answer.
Please ask again, with more detail about what you want/need/have in mind.


Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.


And _this_ sounds like a combination of something that's more
a design issue (the structure) and a trivial implementation
detail (trivial in Python, anyway).

I'll try anyway, as a first test case: put all plugins in a
standard folder, with nothing else present in that folder.
They can be individual modules or packages as you will.
The code to load the plugin consists of an __import__...
and not much else.

Maybe this feedback will help you refine the question further...

-Peter
Jul 18 '05 #4

Reinhold Birkenfeld <re************************@wolke7.net> wrote:

Irmen de Jong wrote:
Reinhold Birkenfeld wrote:
How would you implement a plugin system (for a web-based application)?


This is so general a question that I cannot think of anything concrete to answer.
Please ask again, with more detail about what you want/need/have in mind.


Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.


...Have a place for plugins
app/plugins

...Load the plugins on startup
import traceback
import os
for fn in os.listdir('plugins'):
if fn[:1] != '_' and fn.split('.')[-1] in ('py', 'pyw'):
try:
globals()[fn] = \
__import__('plugins.%s'%fn, globals(), locals(), [fn])
except:
traceback.print_exc()

Etcetera. May not be the best, but it will get the job done.

- Josiah

Jul 18 '05 #5

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:Rp********************@powergate.ca...
Reinhold Birkenfeld wrote:
Irmen de Jong wrote:
Reinhold Birkenfeld wrote:

How would you implement a plugin system (for a web-based application)?

This is so general a question that I cannot think of anything concrete to
answer.
Please ask again, with more detail about what you want/need/have in mind.
Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.


And _this_ sounds like a combination of something that's more
a design issue (the structure) and a trivial implementation
detail (trivial in Python, anyway).

I'll try anyway, as a first test case: put all plugins in a
standard folder, with nothing else present in that folder.
They can be individual modules or packages as you will.
The code to load the plugin consists of an __import__...
and not much else.


I have done something similar, with a few differences. I am using a
convention that all the plugins are implemented as a class with a specific
name ("Handler" in my case), each plugin in its own module (so each Handler
class is scoped by its module). I import all the modules in the directory
dedicated to plugins and I do the following checks: the module contains a
class Handler, the module is not the one implementing the base class itself
(bit of a hack, I admit), and the Handler class is a subclass of the base
class (use isinstance). The checks allow to have also other modules in the
plugins directory that do not actually implement a plugin (for instance, I
have a mixin class in that same directory).

Because you have both plugins and sub-plugins you may want to use some
checks like mine, so you have both plugins and sub-plugins in the same
directory, but you select only the plugin classes. That's if I understand
your requirements correctly.

Dan
Maybe this feedback will help you refine the question further...

-Peter

Jul 18 '05 #6
On Sat, 30 Oct 2004 07:58:27 -0700, Josiah Carlson wrote:

Reinhold Birkenfeld <re************************@wolke7.net> wrote:

Irmen de Jong wrote:
> Reinhold Birkenfeld wrote:
>
>> How would you implement a plugin system (for a web-based application)?
>
> This is so general a question that I cannot think of anything concrete to answer.
> Please ask again, with more detail about what you want/need/have in mind.


Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.


...Have a place for plugins
app/plugins

...Load the plugins on startup
import traceback
import os
for fn in os.listdir('plugins'):
if fn[:1] != '_' and fn.split('.')[-1] in ('py', 'pyw'):
try:
globals()[fn] = \
__import__('plugins.%s'%fn, globals(), locals(), [fn])
except:
traceback.print_exc()

Etcetera. May not be the best, but it will get the job done.

- Josiah


Just FYI, dynamically loaded plugins will not be caught by tools like
py2exe. Another mechanism, which may be more py2exe friendly, is to make
a tool which dynamically creates a python file, which lists all of the
imports. That way, you import the dynamically created file, but once it's
created, you immediately leverage the file for use with py2exe, which can
now follow all of the imports.

Of course, if you never plan on being a py2exe user, you can happily
ignore my ramblings. ;)

Cheers,

Greg
Jul 18 '05 #7

"Dan Perl" <da*****@rogers.com> wrote in message
news:CJ********************@rogers.com...

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:Rp********************@powergate.ca...
Reinhold Birkenfeld wrote:
Irmen de Jong wrote:
Reinhold Birkenfeld wrote:

>How would you implement a plugin system (for a web-based application)?

This is so general a question that I cannot think of anything concrete
to answer.
Please ask again, with more detail about what you want/need/have in
mind.

Okay, the question is too open: My focus is on how you would structure
the plugin code (directories, files) and how you would write code to
load these plugins.
And _this_ sounds like a combination of something that's more
a design issue (the structure) and a trivial implementation
detail (trivial in Python, anyway).

I'll try anyway, as a first test case: put all plugins in a
standard folder, with nothing else present in that folder.
They can be individual modules or packages as you will.
The code to load the plugin consists of an __import__...
and not much else.


I have done something similar, with a few differences. I am using a
convention that all the plugins are implemented as a class with a specific
name ("Handler" in my case), each plugin in its own module (so each
Handler class is scoped by its module). I import all the modules in the
directory dedicated to plugins and I do the following checks: the module
contains a class Handler, the module is not the one implementing the base
class itself (bit of a hack, I admit), and the Handler class is a subclass
of the base class (use isinstance). The checks allow to have also other
modules in the


I forgot what I'm doing in my own code. I looked at it again and found that
I'm not using isinstance(), instead I am doing a check for
"baseClass.Handler in hndlrCls.__bases__", which is much better, because it
doesn't need the creation of an instance. Here is the actual code (my
handlers are the equivalent of your plugins):
# Build a list of the modules that contain a valid Handler class.
hndlrList = []
for hndlrFile in glob.glob(
os.path.join(os.environ['zigzag_install_dir'], 'handlers',
'*.py')):
modName = os.path.split(os.path.splitext(hndlrFile)[0])[1]
if modName == 'baseClass' or \
modName == 'handlerTemplate':
continue
impMod = __import__('handlers.'+modName,
globals(),
locals(),
['Handler'])
if not vars(impMod).has_key('Handler'):
continue
hndlrCls = vars(impMod)['Handler']
if not baseClass.Handler in hndlrCls.__bases__:
continue
hndlrList.append(modName)

baseClass.Handler is the base class for all my handlers.
plugins directory that do not actually implement a plugin (for instance, I
have a mixin class in that same directory).

Because you have both plugins and sub-plugins you may want to use some
checks like mine, so you have both plugins and sub-plugins in the same
directory, but you select only the plugin classes. That's if I understand
your requirements correctly.

Dan
Maybe this feedback will help you refine the question further...

-Peter


Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rudolf | last post by:
Dear NG, I want to create a Plugin System in C# (WinForms). Has anybody experience about this, tips, tricks, or any links. Thank you very much The DotNetJunkie
2
by: Matt | last post by:
I'm hoping someone can steer me in the right direction to try to do the following: I am developing an application where we receive files from customers. Right now we receive a variety of...
0
by: David Levine | last post by:
This is a lengthy post; please bear with me... This will be a large system with dozens of plugins. In addition to plugins developed internally there will be 3rd parties that will write their own...
2
by: Edvard Majakari | last post by:
Hi, My idea is to create a system working as follows: each module knows path to plugin directory, and that directory contains modules which may add hooks to some points in the code. Inspired...
3
by: auad | last post by:
hi, I'm having a problem with plugins....as follows: I have 3 projects: 2 class libraries and 1 Windows App (Project 1: ClassLibrary) I have a plugin interface:...
0
by: Zeya | last post by:
Situation: Using C#, ASP.Net Requirement: 1. ASP.net application with virtual hosting service. 2. Requires a service that will run every predefined frequency in minutes (2, 30, 100, 10000)...
8
by: Flavio | last post by:
Hi, Nowadays the addition of functionality to programs by means of plugins is very frequent. I want to know the opinions of experienced Python developers about the best practices when it...
0
by: Shiplu | last post by:
Hi, I think you are familier with plugin system in windows application. I have created and application which has this facility. One is PluginHost, container of the plugin. Other is Plugin itself....
7
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. I found this out...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.