[Twisted-Python] twisted.plugin issues

Jean-Paul Calderone exarkun at divmod.com
Sat Jun 30 21:32:32 EDT 2007


On Sat, 30 Jun 2007 20:27:19 -0400, Phil Christensen <phil at bubblehouse.org> wrote:
>Hello all,
>
>I'm trying to implement a plugin system in a project using the  twisted 
>plugin framework. I've read through the docs pretty  thoroughly, but I can't 
>seem to figure out what I'm doing wrong.
>
>Attached is a sample case that should illustrate the problem. The  layout is 
>as follows:
>
>     plugin_dir/
>     plugin_dir/test/
>     plugin_dir/test/plugins/
>     plugin_dir/test/plugins/myplugin.py
>     test/
>     test/__init__.py
>     test/plugins/
>     test/plugins/__init__.py
>     test/sample.py
>     test_plugin.py
>
>First I created the test.plugins package, and included the following  in 
>test/plugins/__init__.py:
>
>     import os, sys
>
>     __path__ = [os.path.abspath(os.path.join(x, 'test', 'plugins'))
>                     for x in sys.path]
>
>     __all__ = []
>
>Then I created my interfaces in the test.sample module:
>
>     from zope import interface
>
>     class ISamplePlugin(interface.Interface):
>         '''My Sample Plugin Class'''
>
>Next, I created the plugin in an arbitrary directory, under 
>plugin_dir/test/plugins/myplugin.py:
>
>     from zope.interface import implements
>     from twisted import plugin
>     from test.sample import ISamplePlugin
>
>     class MyPlugin(object):
>         implements(plugin.IPlugin, ISamplePlugin)

The problem may be here.  What happens if you use classProvides instead of
implements or bind an instance of MyPlugin to an attribute of this module?

>
>Finally, here's the sample script that tries to load the plugins in  the 
>arbitrary directory:
>
>     from twisted import plugin
>
>     import sys
>     sys.path.append('.')
>     sys.path.append('./plugin_dir')
>
>     from test import sample, plugins
>     from twisted import plugin
>     plugin_result = plugin.getPlugins(sample.ISamplePlugin, plugins)
>
>     for plugin in plugin_result:
>         print repr(plugin) + ' was found.'
>
>Which gives no output.
>
>Here are the things I've checked for:
>
>     * './plugin_dir' is definitely on the pythonpath when
>       getPlugins is called. I've also tried using an absolute path.
>
>     * once the path is modified, I can import manually with:
>         import test.plugins.myplugins
>
>I'm using the latest Twisted-SVN, under the pythonmac.org Python  2.4.4 
>distribution on Mac OS X 10.4.10.
>
>Any help would be greatly appreciated.
>
>Thanks in advance,
>

Jean-Paul




More information about the Twisted-Python mailing list