编写 Bazaar 插件 - 注册命令?
我在编写 Bazaar 插件时遇到问题。
我一直在尝试一些不同的事情,这是我的文件的当前状态:
''' 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)
这是当我尝试执行我的命令时发生的情况:
$bzr test-foo
hi
bzr: ERROR: unknown command "test-foo"
所以这真的很奇怪 - 它显然正在运行我的命令,但告诉我它是未知的?
有没有好的插件示例来源?我按照建议查看了 builtins.py
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我在网络或 SO 上找不到有关此错误的任何真实信息,因此我决定发布并回答我自己的问题。
当 Bazaar 导入插件时,它会创建一个 .pyc 文件,就像通常从 Python 导入一样。如果发生一些神奇的事情 - 比如在一个目录中编辑它并忘记复制它,然后创建一个符号链接 - 它永远不会导入修改。 bazaar 需要调用
register_command(cmd_test_foo)
来注册命令,其中 cmd_test_foo 是您的命令名称。当您调用 bzr 帮助命令时,它也会像这样显示:当然,
在最后一个命令上您还会看到您可能安装的任何其他插件。
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:and also
of course on that last one you'll also see any other plugins you may have installed.