[Twisted-Python] twisted.plugin plugin framework
Matt Goodall
matt at pollenation.net
Mon May 23 13:24:58 MDT 2005
Nathaniel Haggard wrote:
> 1. What is/was the purpose of twisted.plugin?
It is for loading plugins! ;-)
>
> 2. "mypkg" is a directory containing __init__.py
>
> __init__.py contains:
>
> import twisted.plugin
> import zope.interface as z
> import twisted.plugin as p
>
> class Beta:
> z.implements(p.IPlugin)
>
> class Gamma:
> """This is the doc string"""
>
> __implements__ = p.IPlugin
>
> -----------------
>
> Trying to load the package with getPlugins returns an empty generator
> as far as I can tell
OK, the main thing is that t.plugin loads *instances* of IPlugin
implementing classes. It does not find classes with an implements(IPlug)
and create instances for you.
Something like:
class Beta:
z.implements(p.IPlugin)
betaPlugin = Beta()
will /probably/ be enough for t.plugin to find them. However, you almost
certainly want your plugins to implement another, application specific,
more interesting interface too, i.e.
class ISomething(Interface):
pass
class Beta:
z.implements(p.IPlugin, ISomething)
betaPlugin = Beta()
You can then search for ISomething plugins, which is much more
meaningful than searching for any (i.e IPlugin) plugin.
plugins = twisted.plugin.getPlugins(ISomething, mypkg)
Hope that helps.
Cheers, Matt
>
>
> import twisted.plugin
> import mypkg
>
> l = twisted.plugin.getPlugins(twisted.plugin.IPlugin, mypkg)
> print dir(l)
> for i in l:
> .....
>
> Actually twisted.plugin.getCache doesn't return anything for
> getPlugins to get. Am I setting up the package incorrectly?
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: matt at pollenation.net
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.
More information about the Twisted-Python
mailing list