Re: [Twisted-Python] twisted.plugin question

"glyph" == glyph <glyph@divmod.com> writes: glyph> On Thu, 15 Jun 2006 17:09:26 +0200, Terry Jones <terry@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 glyph> plugin. OK, I see now how that's working, thanks.
def displayAllKnownMaterials(): for material in getPlugins(IMaterial): displayMaterial(material)
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 there.
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> unique. OK, done. glyph> from myapp import main glyph> 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. Terry
participants (1)
-
Terry Jones