[Twisted-Python] twisted.plugin issues
Phil Christensen
phil at bubblehouse.org
Sat Jun 30 23:57:13 EDT 2007
On Jun 30, 2007, at 9:32 PM, Jean-Paul Calderone wrote:
> 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?
Aha, this looks promising. Doing either of those things results in:
Traceback (most recent call last):
File "test_plugin.py", line 11, in ?
for plugin in plugin_result:
File "/Users/phil/Workspace/Twisted/twisted/plugin.py", line 186,
in getPlugins
allDropins = getCache(package)
--- <exception caught here> ---
File "/Users/phil/Workspace/Twisted/twisted/plugin.py", line 165,
in getCache
dropinPath.setContent(pickle.dumps(dropinDotCache))
cPickle.PicklingError: Can't pickle <InterfaceClass
test.sample.ISamplePlugin>: import of module test.sample failed
<class 'test.plugins.myplugin.MyPlugin'> was found.
So this must be pretty close. I tried deleting the dropin.cache, but
I'm still getting this exception.
>>
>> 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.'
>>
More information about the Twisted-Python
mailing list