[Twisted-Python] twisted.plugin question
terry at jon.es
Thu Jun 15 16:38:52 EDT 2006
>>>>> "glyph" == glyph <glyph at divmod.com> writes:
glyph> On Thu, 15 Jun 2006 17:09:26 +0200, Terry Jones <terry at jon.es> wrote:
>> sys.path[:0] = ['./twisted/plugins']
glyph> This line is unnecessary, and probably wrong. If you look in
glyph> twisted/plugins/__init__.py, you will notice that it puts any
glyph> additional entries on sys.path into its __path__; the fact that "."
glyph> is already on your sys.path is enough for it to recognize this
OK, I see now how that's working, thanks.
>> def displayAllKnownMaterials():
>> for material in getPlugins(IMaterial):
glyph> This is going to look for plugins in twisted.plugins, which is
glyph> probably not what you want. Did you look under the "alternate
glyph> plugin packages" section of that document?
I did, and it seemed relevant, but I didn't understand it. The page says
"If passed in, the 2nd argument should be a module or package to be used
instead of twisted.plugins as the plugin meta-package." I had no idea what
such a module or package should do! Reading the section above seemed to
make it clear that I could mkdir -p twisted/plugins and drop my code in
>> from twisted.plugin import IPlugin
>> from plugin import IMaterial
glyph> There is some vagueness in naming here. Depending on your working
glyph> directory (etc) twisted.plugin might be picked up as plugin. You
glyph> probably want to change the name of your example module to something
glyph> from myapp import main
glyph> Python has the unfortunate habit of creating a special module called
glyph> "__main__" and putting the code from the file it is passed onto the
glyph> commandline into that module, rather than into the location where it
glyph> would go if you imported it; having two copies of your "plugin"
glyph> module in memory at once (the imported one, and the __main__ one) is
glyph> probably causing at least some of your problems.
And thanks for this too. I'm very new to python, and I had no idea.
The code is now working.
More information about the Twisted-Python