[Twisted-Python] twisted.plugin issues

Phil Christensen phil at bubblehouse.org
Sat Jun 30 20:27:19 EDT 2007


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)

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,

-phil



-------------- next part --------------
A non-text attachment was scrubbed...
Name: plugin_test.tgz
Type: application/octet-stream
Size: 675 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20070630/3af90d99/attachment.obj 


More information about the Twisted-Python mailing list