I'm trying to follow the sample code for writing Mercurial extensions. This is a minimal sample, copied verbatim from the sample code:
from mercurial import cmdutil
from mercurial.i18n import _
cmdtable = {}
command = cmdutil.command(cmdtable)
I save this to a file and install the extension in my .hgrc
file like so:
[extensions]
myext=C:\foo\myext.py
Any subsequently issued command, like e.g. hg init
now results in the following error message:
*** failed to import extension myext from C:\foo\myext.py: 'module' object has no attribute 'command'
Could this possibly be caused by a faulty environment, e.g. missing environment variables?
I'm using Mercurial 4.7 on Windows 10, installed by the TortoiseHg installer (tortoisehg-4.7.0-x64). Mercurial uses Python 2.7.13, also installed by the TortoiseHg installer.
It looks like the documentation needs to be updated. command
was 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.
The Mercurial 4.7 release in August, 2018 included the change that removed cmdutil.command
:
cmdutil: drop deprecated precursor of registrar.command (API)
This works for me:
from mercurial import registrar
from mercurial.i18n import _
cmdtable = {}
command = registrar.command(cmdtable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With