[MERGE] allow 'import bzrlib.plugins.NAME'

John Arbash Meinel john at arbash-meinel.com
Fri Feb 2 20:25:21 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert Collins wrote:
> On Fri, 2007-02-02 at 14:07 -0600, John Arbash Meinel wrote:
> 
>> What is the traceback in ~/.bzr.log? Having "unable to load" at least
>> tells someone something is wrong.
>>
>> If you are going to have a check, I would actually prefer:
>>
>> if not re.match('\w+'):
>>   warning('Unable to load plugin %r from %r: '
>>           'It is not a valid python module name.' % (name, d))
>>
>> That way we handle 'foo.bar' which is also invalid. And might actually
>> cause problems based on what you are doing (import bzrlib.foo.bar)
>> imports something different.
> 
> Discussed on irc: re.search('\.-') is a good start.
>> __import__ returns something different than 'import' does. I think it
>> has more to do with what it does to locals() and globals() than anything
>> else.
>>
>> I just avoid exec() and eval(). If I see it, it makes me wonder if the
>> code is correct.
> 
> import is a statement, I dont think it returns anything.
> 
> I'll change it to 'exec "import bzrlib.plugins.%s" % name in {}' to
> address any chance of it altering the current namespace.
> 
> Ok now?
> -Rob
> 

'import' causes the imported thing to appear in the local (global?)
namespace. Ie

import foo

foo.bar()

So it has some side effects. __import__('foo') returns foo, but does not
change the namespace.

The biggest differences are in things like __import__('foo.bar') versus
__import__('foo', globals(), locals(), ['bar']) and some other more
complex ways of invoking them.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFw54xJdeBCYSNAAMRAkPWAJ9YCzmFCsSDSPAT/r8uh9CxgSfW1wCg0DrB
JacsGG2uEoF8MAnpdnylk8w=
=sCvd
-----END PGP SIGNATURE-----



More information about the bazaar mailing list