On Wed, 10 Dec 2008 12:13:28 +0000 Matt Nordhoff <[EMAIL PROTECTED]> wrote:
> Julian Smith wrote: > > I don't seem to be able to use the `email' module from within a bazaar > > plugin. Other modules work ok, e.g. nntplib. > > > > Here's my plugin, cut-down to show just the email problem: > > > > import sys > > print 'sys.version', sys.version > > > > import nntplib > > n = nntplib.NNTP( 'jsmith-ubuntu2' ) > > print n > > > > import email > > m=email.MIMEText.MIMEText('text of email') > > > > - and here's the output when i run any bazaar command: > > > > > bzr status > > sys.version 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] > > <nntplib.NNTP instance at 0xb7b1082c> > > 'module' object has no attribute 'MIMEText' > > Unable to load plugin 'js_notify' from '/home/jsmith/.bazaar/plugins' > > ... > > > > The plugin runs fine on its own, it's only when loaded into Bazaar that > > things > > go wrong. > > > > I thought perhaps this could be caused by the `email' module's use of > > LazyImporter. I've tried various things such as `from email.mime.text import > > MIMEText', and they fail in similar ways. > > > > I'm using bzr-1.9, python 2.5.2, on Ubuntu-8.xx. > > > > Does anyone have any ideas ? > > > > Thanks, > > > > - Julian > > The built-in email module is probably getting shadowed by another one > (perhaps bzrlib.plugins.email?), so "import email" is importing the > wrong module. You'll have to rename it to something else. > > Have your plugin print email.__path__ to see which module it is. Ah, you're quite right. Curiously, email.__path__ is: /usr/lib/python2.5/site-packages/bzrlib/plugins/email - but sys.path is: ['/usr/bin', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/site-packages/gst-0.10', '/var/lib/python-support/python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/var/lib/python-support/python2.5/gtk-2.0'] - i.e. no occurrence of `/usr/lib/python2.5/site-packages/bzrlib/plugins'. So i guess bazaar is redefining __import__() to look in the the plugins directory first, or something. Anyway, I can get things to work with the following: import imp email = imp.load_module( 'email', *imp.find_module( 'email', sys.path)) Many thanks, - Julian -- http://op59.net/ -- http://mail.python.org/mailman/listinfo/python-list