[PATCH] python plugins in BZRPATH using Command structure
John A Meinel
john at arbash-meinel.com
Mon May 23 18:26:03 BST 2005
Aaron Bentley wrote:
> mbp at sourcefrog.net wrote:
> | Why not just list them directly on your path?
>
> You might as well ask 'why not list the plugin filenames directly'?
>
> I like plugin systems that support the 'dump it in a directory and
> you're done' approach. I think that's convenient and understandable.
> This system supports that, but only for files.
>
> It would also be nice to support updating your plugins with bzr. But
> bzr only does updates in terms of working trees, not files. So if we
> want to allow people to
>
> 1. install plugins with minimum fuss
> 2. update plugins using bzr
>
> then I think the obvious way is to allow working trees to be placed in
> plugin directories.
>
> Aaron
I've been thinking about it, what if we support "__init__.py" for
directories.
So you have BZRPLUGINPATH which can contain .py files, but can also
contain directories. If the directory has an __init__.py file, the
directory will be imported just like all the other files. It means that
the person working on the bzr tree needs to add
from newcommand import *
to __init__.py whenever they add a new command to their project.
This is one possibility.
One small fix that I probably need to add is to handle having files with
the same name. By default 'import' caches the module in sys.modules so
that re-importing something with the same name gives the same module.
Since I am messing with sys.path so that I can dynamically import from a
new directory, if there are 2 files with the same name they potentially
conflict.
Actually, I think __init__.py fixes this problem, since in that
circumstance it makes the import get a prefix (so if in test/__init__.py
you import bzrlib it shows up in sys.modules as test.bzrlib).
If you wanted to be cruel, you could make BZRPLUGINPATH use __init__.py,
but then the person needs to manually update it, rather than just drop
in a file.
My current favorite is to just use what we I wrote. bzr searches all of
BZRPLUGINPATH, and recurses 1 directory to look for .py files, which it
then imports and looks for cmd_* functions. If it finds any, it adds
them to the command list.
I'm flexible, but since we have ExternalCommands added, I would really
like to see python native plugins also exist somehow in bzr proper.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050523/aae1b10a/attachment.pgp
More information about the bazaar
mailing list