[PATCH 1 of 2] hglib: handle moving `mercurial.rcutil` to `mercurial.configuration.rcutil`

3 views
Skip to first unread message

Matt Harbison

unread,
Feb 20, 2025, 11:24:57 PMFeb 20
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1735114105 18000
# Wed Dec 25 03:08:25 2024 -0500
# Branch stable
# Node ID 9563728ec05f250ece22b6de3cee2efe6e1895cf
# Parent ae2a656dc16741b44e253eaa4a879ecb87f24291
# EXP-Topic hg-7.0-changes
hglib: handle moving `mercurial.rcutil` to `mercurial.configuration.rcutil`

The goofy definition stub is so that pytype doesn't merge an unknown with the
function signature that it sees in the new module, and type it as `Any`. If the
real definition changes, it should type the symbol as a union of the two
signatures, and hopefully that's good enough to notice the change.

diff --git a/tortoisehg/util/hglib.py b/tortoisehg/util/hglib.py
--- a/tortoisehg/util/hglib.py
+++ b/tortoisehg/util/hglib.py
@@ -14,6 +14,7 @@
import shlex
import sys
import time
+import typing

from typing import (
cast,
@@ -39,7 +40,6 @@
patch as patchmod,
pathutil,
pycompat,
- rcutil,
revset as revsetmod,
revsetlang,
scmutil,
@@ -64,6 +64,20 @@
ngettext as _ngettext,
)

+# pytype: disable=import-error
+try:
+ from mercurial.configuration import rcutil
+ userrcpath = rcutil.userrcpath # defeat demandimport
+except (ImportError, AttributeError):
+ # hg < 7.0 (0a81f3ef054c)
+ from mercurial import rcutil
+ userrcpath = rcutil.userrcpath
+
+ if typing.TYPE_CHECKING:
+ def userrcpath() -> list[bytes]:
+ raise NotImplementedError
+# pytype: enable=import-error
+
TYPE_CHECKING = getattr(pycompat, 'TYPE_CHECKING', False)

if TYPE_CHECKING:
@@ -102,7 +116,6 @@

extractpatch = patchmod.extract
tokenizerevspec = revsetlang.tokenize
-userrcpath = rcutil.userrcpath

# TODO: use unicode version globally
def _(message: str, context: str = '') -> bytes:

Matt Harbison

unread,
Feb 20, 2025, 11:25:04 PMFeb 20
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1740106865 18000
# Thu Feb 20 22:01:05 2025 -0500
# Branch stable
# Node ID 45687a05969206134cf121f03157870e78a85b23
# Parent 3b34b566fbab181836f669780e94571b6d58851f
# EXP-Topic hg-7.0-changes
serve: refactor a function to help pytype

Somehow, upgrading to Python 3.11 to run pytype caused it to complain that:

File "/home/mharbison/projects/mercurial/thg/tortoisehg/hgqt/serve.py", line 144,
in _tempwebconf: No attribute 'write' on mercurial.config.config [attribute-error]
In Union[mercurial.config.config, tortoisehg.util.wconfig._wconfig]
Called from (traceback):
line 130, in _cmdargs

diff --git a/tortoisehg/hgqt/serve.py b/tortoisehg/hgqt/serve.py
--- a/tortoisehg/hgqt/serve.py
+++ b/tortoisehg/hgqt/serve.py
@@ -132,16 +132,17 @@

def _tempwebconf(self) -> Text:
"""Save current webconf to temporary file; return its path"""
- if not hasattr(self._webconf, 'write'):
- return hglib.tounicode(self._webconf.path) # pytype: disable=attribute-error
+ webconf = self._webconf
+ if not hasattr(webconf, 'write'):
+ return hglib.tounicode(webconf.path) # pytype: disable=attribute-error

- assert isinstance(self._webconf, wconfig._wconfig) # help pytype
+ assert isinstance(webconf, wconfig._wconfig) # help pytype

fd, fname = tempfile.mkstemp(prefix=b'webconf_',
dir=qtlib.gettempdir())
f = os.fdopen(fd, 'w')
try:
- self._webconf.write(f)
+ webconf.write(f)
return hglib.tounicode(fname)
finally:
f.close()

Matt Harbison

unread,
Feb 20, 2025, 11:28:08 PMFeb 20
to TortoiseHg Developers
6.9.2 was tagged the other day, and 7.0 has a lot of changes around not calling setup.py directly for PEP 517 support.  So even though there weren't a lot of thg changes since 6.9, it might make sense to tag a 6.9.2 release before landing these.  I'm not sure how much work it will be to adapt to the setup.py changes yet.

Yuya Nishihara

unread,
Feb 21, 2025, 10:26:09 AMFeb 21
to Matt Harbison, thg...@googlegroups.com
On Thu, 20 Feb 2025 23:24:45 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_h...@yahoo.com>
> # Date 1735114105 18000
> # Wed Dec 25 03:08:25 2024 -0500
> # Branch stable
> # Node ID 9563728ec05f250ece22b6de3cee2efe6e1895cf
> # Parent ae2a656dc16741b44e253eaa4a879ecb87f24291
> # EXP-Topic hg-7.0-changes
> hglib: handle moving `mercurial.rcutil` to `mercurial.configuration.rcutil`

Queued, thanks.
Reply all
Reply to author
Forward
0 new messages