[Tutor] Plugin system - how to manage plugin files?

Mac Ryan quasipedia at gmail.com
Thu Jul 29 01:34:07 CEST 2010


On Wed, 2010-07-28 at 13:53 -0500, Scott Nelson wrote:
> On Wed, Jul 28, 2010 at 10:07 AM, Mac Ryan <quasipedia at gmail.com>
> wrote:
>         Hi everybody,
>         
> 
> Mac,
> 
> I don't know if this is exactly what you are after, but I created a
> poor-man's plugin system by simply putting .py files into the same
> directory as my app and naming them like xxxx_plugin.py  Each of
> these .py "plugins", had to define a class named "Plugin" that had
> some set of expected methods and properties (ex: initialize(), run(),
> etc.).  Then, when my app started up, it simply got a list of all the
> "*_plugin.py" files in the current directory, dynamically imported the
> files using "my_module = __import__(name)" and then I could do
> whatever I wanted with that module using "my_module", such as
> instantiate an object for each module's "Plugin" class, etc.
> 
> Actually, here's a snippet of code I had lying around that I slapped
> together a few years ago to remind myself of how I did this.  I can't
> promise this is 100% tested, but it should give you an idea.
> 
> http://pastebin.com/UtVp6J9j
> 
> Also, you might want to look at this discussion:
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ba8d361516403fdf/
> 
> Best of luck!
> 
> -Scott

Thank you Scott for your reply,

I inspected the code you pastebin'd, but I am under the impression the
solution you proposed present about the same shortcomings that mines... 

I recognise that the naming convention of files solve the problem of
having in the same place files which might not be plugins, but the
naming convention is an imposition that I would rather try not to impose
to other devs, the reson being that in my application plugins get
subclassed, so that - if the name of the plugin must be relevant - names
would end up being something like:

   medianvalues_gtk_statistics_scores_plugin.py 

where "medianvalues" would be the name of the plugin, an each other
underscore-separated word would be a parent class.

My hope is that somebody will show me some "automagic obscure voodoo
method" (I am thinking to some "__real_vooodoo__" method or function
somewhere in the module file or in the __init__.py file of the packages)
that will be able to provide information on the plugin without actually
loading it...

Let's see if somebody else will reply to this [admittedly
not-so-popular] thread! ;)

Mac.

PS: About the thread that you linked in your reply: my solution is in
the line of what Fredrik Lundh proposed, using __metaclass___



More information about the Tutor mailing list