[MERGE] make plugins use the right suffixes

Robert Collins robertc at robertcollins.net
Tue Aug 1 06:30:21 BST 2006


On Mon, 2006-07-31 at 18:54 -0500, John Arbash Meinel wrote:
> John Arbash Meinel wrote:
> > Robert noticed that we would allow loading '.pyo' files even if we
> > weren't running python -O. (it turns out python won't load .pyc if
> > running -O, and won't load .pyo if running without it.)
> > 
> > The attached bundle fixes it to use the right suffixes.
> > 
> 
> ...
> 
> Now with a real patch :)
> 
> Available from:
> 
> http://bzr.arbash-meinel.com/branches/bzr/features/plugin-imports


Thanks. I'm going to merge this as is. I've looked at imp a bit more
though and I think we can be a *lot* cleaner in 0.10:

For instance:

>>> import imp
>>> # handwave - do a directory listing of both system plugins and user
>>> # plugins and strip back the paths to the first '.'. Then:
>>> for name in candidate_set:
>>>     try:
>>>         mod_info = imp.find_module(name, [user_plugin_dir,
system_plugin_dir])
>>>     except ImportError:
>>>         # no module by this name -
>>>         mutter()
>>>     module = imp.load_module('bzrlib.plugins.' + name, mod_info[0],
mod_info[1], mod_info[2])
>>>     setattr('bzrlib.plugins', name, module)

That should be all we need to do. find_module takes care of pyo vs pyc
vs __init__ etc etc etc.

Now, we can go a step further and get 'import bzrlib.plugins.pluginname'
working.

All this takes is (in bzrlib/__init__.py):
import bzrlib.plugins
bzrlib.plugins.__path__ = [per_user_path, system_path]

(This is supported and intentional according to PEP 302). This would
make our 'load all plugins' code be:

>>> import imp
>>> # handwave - do a directory listing of both system plugins and user
>>> # plugins and strip back the paths to the first '.'. Then:
>>> for name in candidate_set:
>>>     try:
>>>         mod_info = imp.find_module(name, [user_plugin_dir,
system_plugin_dir])
>>>     except ImportError:
>>>         # no importable module by this name.
>>>     good_modules.append(name)
>>> for name in good_modules:
>>>    try:
>>>        __import__('bzrlib.plugins.' + name, globals(), locals(), [])
>>>    except ImportError, error:
>>>        mutter(... error)

This should be done for 0.10 IMO. It has a number of ramifications:
 * the disk name for plugins should be valid python identifiers. I think
this is a good thing.
 * module load order will become nondeterministic unless we explicitly
sort the set. I think this is a good thing too - for overloading
commands we need a better mechanism than renaming modules - because
renaming breaks code sharing between plugins.
 * we wont support 'foomodule.so' style plugins - but as its our plugin
system I don't think that is a big loss.

and the big one:
 * plugins can now share code between each other, so you can have a
plugin (for instance) 'bzrlib.plugins.graphcore' which the plugins
'bzrk', 'olive' both import functionality from.

In terms of user experience, dropping a plugin to a specific name on
disk should not be hard at all. We can add a runtime check to see its
been done right - just check an attribute in the plugin for its expected
name. Where plugins do share code the user will need to install both
(naturally), but for a distribution shipping plugins into the system
path this should make things easier as well - they can package each bit
separately.

Rob



-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060801/113700ac/attachment.pgp 


More information about the bazaar mailing list