编写 Bazaar 插件 - 注册命令?

发布于 2024-09-05 19:02:59 字数 884 浏览 2 评论 0原文

我在编写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪推晚风 2024-09-12 19:02:59

由于我在网络或 SO 上找不到有关此错误的任何真实信息,因此我决定发布并回答我自己的问题。

当 Bazaar 导入插件时,它会创建一个 .pyc 文件,就像通常从 Python 导入一样。如果发生一些神奇的事情 - 比如在一个目录中编辑它并忘记复制它,然后创建一个符号链接 - 它永远不会导入修改。 bazaar 需要调用 register_command(cmd_test_foo) 来注册命令,其中 cmd_test_foo 是您的命令名称。当您调用 bzr 帮助命令时,它也会像这样显示:

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

当然,

$ bzr plugins
testCmd 0.0.1.dev
    Testing Bzr plugins

在最后一个命令上您还会看到您可能安装的任何其他插件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文