我正在尝试按照writing Mercurial extensions的示例代码。这是一个最小的样本,从示例代码中逐字复制:
from mercurial import cmdutil
from mercurial.i18n import _
cmdtable = {}
command = cmdutil.command(cmdtable)
我将其保存到文件并在我的.hgrc
文件中安装扩展名,如下所示:
[extensions]
myext=C:\foo\myext.py
随后发布的任何命令,例如hg init
现在导致以下错误消息:
***无法从C:\ foo \ myext.py导入扩展名myext:'module'对象没有属性'command'
这可能是由一个有缺陷的环境引起的,例如:缺少环境变量?
我在Windows 10上使用Mercurial 4.7,由TortoiseHg安装程序(tortoisehg-4.7.0-x64)安装。 Mercurial使用Python 2.7.13,也是由TortoiseHg安装程序安装的。
看起来文档需要更新。 command
是moved from cmdutil
to registrar
in January, 2016,虽然当时留下了别名。这是marked as deprecated in November, 2017和removed entirely in May, 2018。
Mercurial 4.7 release in August, 2018 included the change that removed cmdutil.command
:
cmdutil:drop不推荐使用registrar.command(API)的前身
这对我有用:
from mercurial import registrar
from mercurial.i18n import _
cmdtable = {}
command = registrar.command(cmdtable)