Plugin framework - Overcomplicating things?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Mar 27 02:31:31 EDT 2008


En Thu, 27 Mar 2008 01:50:56 -0300, hajducko at gmail.com  
<hajducko at gmail.com> escribió:

> All this comes to my question - am I overcomplicating this project? I
> can understand the use of something like the trac component system if
> I had multiple components and plugins that handled different areas of
> my project and different points of interaction, but I don't.  I've got
> exactly one spot where I want to check all my plugins and hand off the
> message to which ever ones are looking for that command.

As you said, it looks like you're really overengineering your design then.

> So really,
> should I even bother with trying to setup some framework for this or
> should I just be doing a simple loop over a directory, importing all
> the plugins and storing them in a list and then looping over them in
> the message handler to see which ones were looking for the command and
> letting them do their thing?

That may be an option.
You may want to setup a simple registry mechanism, so the plugin modules  
look like:

### begin niceplugin.py ###
class AVeryNicePlugin(object): #  or perhaps using a suitable base class
     def handle_message(self, message):
         ...

 from plugin import PluginRegistry
PluginRegistry.register(AVeryNicePlugin)
### end niceplugin.py ###

Your application scans a known directory for files ending in "plugin.py"  
and imports them; the modules register themselves any class (or classes),  
and at appropiate times the application calls some method(s) of the  
registered plugins.

> As an aside, if there is anyone who is an experience developer and
> designer and is willing to take some private correspondence, please
> let me know.  I feel embarrassed for asking, but I've got a alot of
> questions that I don't want to litter this list with and would rather
> voice them in private.

Why not? Get another free account, post using a pseudonym, and nobody will  
know that *YOU* were the guy that asked the most stupid question of the  
week :)

-- 
Gabriel Genellina




More information about the Python-list mailing list