command options in plugins?

John A Meinel john at
Tue Jun 14 17:09:34 BST 2005

Aaron Bentley wrote:

> Hi all,
> Is there a way to specify command options for Python plugins that bzr
> doesn't know about?  Simply adding an entry to bzrlib.commands.OPTIONS
> doesn't work, because plugins are loaded only after parsing is complete.
> I'm trying to provide all the scripts in bzrtools as plugins for the
> next bzrtools release*, but some of the options, like --max-count or
> --skip-symlinks are not standard bzr options.
> It's a bit of a chicken-egg problem, because the --builtin option should
> control whether plugins are loaded and thus, how options are parsed.
> Perhaps it would make sense to handle --builtin before normal option
> parsing.
Actually, I think you are right. The code should look more like:
  if argv[1] != 'builtin':
    argv = argv[2:]
    argv = argv[1:]
  args, opts = parse_args(argv)

This would allow you to add your new option flags into
bzrlib.commands.OPTIONS before parse_args is run.
It would also be better for this to use the _plugins global dictionary,
and possibly the register function that Lalo offered.

What would be nice is some way to have plugins loaded at the same time
that bzrlib is loaded, but you need a way to pass the "don't load
options" to bzrlib.
The only way I can think of to do that is to hijack __builtins__, since
that is the only place for truly global options that can be read at
import time.

Then you would change the "bzr" command line portion with:

if sys.argv[1] == 'builtin':
    __builtin__['bzrlib_no_plugins'] = True
    sys.argv = sys.argv[:1] + sys.argv[2:]
    __builtin__['bzrlib_no_plugins'] = False

And then in "bzrlib/" you could do:
if not __builtin__.has_key('bzrlib_no_plugins') or not

But that is a little bit ugly.

> Aaron
> ---
> * Scripts will also be provided.

I vote for moving the plugin loading into run_bzr() before the
parse_args() command, with an externally viewable function, so that an
alternative client can call "bzrlib.load_plugins()" at an appropriate time.

That allows plugins to hook in before any real work has been done for
the bzr commandline, and external programs can decide if they want to
support plugins or not.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : 

More information about the bazaar mailing list