简单的 Mercurial 扩展无法导入
Simple Mercurial extension fails to import
我正在尝试遵循 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
现在会导致以下错误消息:
*** failed to import extension myext from C:\foo\myext.py: 'module' object has no attribute '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 though an alias was left in place at that time. This was marked as deprecated in November, 2017 and removed entirely in May, 2018。
Mercurial 4.7 release in August, 2018 included the change that removed cmdutil.command
:
cmdutil: drop deprecated precursor of registrar.command (API)
这对我有用:
from mercurial import registrar
from mercurial.i18n import _
cmdtable = {}
command = registrar.command(cmdtable)
我正在尝试遵循 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
现在会导致以下错误消息:
*** failed to import extension myext from C:\foo\myext.py: 'module' object has no attribute '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 though an alias was left in place at that time. This was marked as deprecated in November, 2017 and removed entirely in May, 2018。
Mercurial 4.7 release in August, 2018 included the change that removed cmdutil.command
:
cmdutil: drop deprecated precursor of registrar.command (API)
这对我有用:
from mercurial import registrar
from mercurial.i18n import _
cmdtable = {}
command = registrar.command(cmdtable)