[PATCH] Search user plugin directories before site plugin directories

John Arbash Meinel john at arbash-meinel.com
Fri Feb 23 16:35:04 GMT 2007


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

Aaron Bentley wrote:
> John Arbash Meinel wrote:
>>> Aaron Bentley wrote:
>>>> Aaron Bentley has voted -1.
>>>> Status is now: Vetoed
>>>> Comment:
>>>> This is the wrong way to do it.  Plugins can override existing commands,
>>>> so user plugins should be searched last, so that they can override
>>>> commands supplied by system-wide plugins.
>>> You misunderstand how this code works. This is changing the python
>>> import path.
> 
> If you think that's so, it's you who misunderstands.  This is
> determining the plugin path, not sys.path.
> 
>>> And in the import path the *first* entry wins. Not the last
>>> one.
> 
> This is the plugin path, not the import path, and so we get to determine
> how it works.  I think we should:
> 
> 1. generate a list of all plugins
> 2. where there are name conflicts, choose the last-found plugin
> 3. load all plugins in the list.
> 
>>> This should be re-opened and accepted, rather than vetoed.
> 
> I disagree.  Applying this change would break our existing override
> behavior.
> 
> Aaron

=== modified file bzrlib/plugin.py
- --- bzrlib/plugin.py
+++ bzrlib/plugin.py
@@ -84,8 +84,8 @@
     """Set the path for plugins to be loaded from."""
     path = os.environ.get('BZR_PLUGIN_PATH',
                           get_default_plugin_path()).split(os.pathsep)
- -    # search the bzrlib installed dir before anything else.
- -    path.insert(0, os.path.dirname(plugins.__file__))
+    # search the plugin path before the bzrlib installed dir
+    path.append(os.path.dirname(plugins.__file__))
     plugins.__path__ = path
     return path

^^^^^ This very explicitly sets "bzrlib.plugins.__path__" which affects
how python -c "import bzrlib.plugins.foo" works.

Basically, this is the *same* thing as sys.path. It is just local to a
specific module.

Now, there is a small issue that it is *also* being used as the search
path. However, if you look at the search code it does one loop to find
all possible plugin names, and then a second import which doesn't care
where it was found.

That means that if you have a "bzrlib/plugins/foo" and a
~/.bazaar/plugins/foo it will find the name "foo" and then do:

exec "import bzrlib.plugins.foo"

And at *that* time, it is important that we have ~/.bazaar/plugins in
plugins.__path__ ahead of /usr/lib/.../bzrlib/plugins/

I think you are remembering the old plugin code, which used to look for
plugins, and note what directory it was found in, and then explicitly
load the plugin from that directory.

Robert changed it to use more of a standard "import bzrlib.plugins.foo"
so that plugins could import each other. And as long as they do so after
bzrlib.plugins.__path__ is set, it should "just work".

John
=:->

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

iD8DBQFF3xe4JdeBCYSNAAMRAoKRAJ9Fn1VVzah64Ju7wrdWN9gySJ/ITACgi3gI
yFbbdwU+FRlOfncsLegVtpk=
=ciRe
-----END PGP SIGNATURE-----



More information about the bazaar mailing list