views:

15

answers:

1

Hi,

I'm having a problem with writing my Bazaar plugin.

I've been trying a few different things, and this is the current state of my file:

''' Testing Bzr plugins '''                                                     
from bzrlib.commands import Command, register_command                           

version_info = (0,0,1, 'dev')                                                   

class cmd_test_foo(Command):                                                    
    ''' Testing is painful. '''                                                 

    def run(self):                                                              
        print "hi"                                                

register_command(cmd_test_foo) 

Here's what happens when I try to execute my command:

$bzr test-foo
hi
bzr: ERROR: unknown command "test-foo"

So that's really weird - it's obviously running my command, but tells me it's unknown?

Are there any good sources for plugin examples? I've looked at the builtins.py as suggested here but nothing there seemed to help.

+1  A: 

Since I couldn't find any real information on this error on the web or SO, I decided I should post and answer my own question.

When Bazaar imports a plugin it creates a .pyc file just like normally importing from Python. If something magical happens - like editing it in one directory and forgetting to copy it, and then creating a symlink - it will never import the modifications. The register_command(cmd_test_foo) call is necessary for bazaar to register the command, where cmd_test_foo is your command name. When you call bzr help commands it will also show up like so:

$ bzr help commands
... (snip commands)
test-foo         Testing is painful.  [testCmd]
... (snip other commands)

and also

$ bzr plugins
testCmd 0.0.1.dev
    Testing Bzr plugins

of course on that last one you'll also see any other plugins you may have installed.

Wayne Werner