Patchwork [1,of,5] setup: avoid attempting to invoke the system-wide hg.exe on Windows

login
register
mail settings
Submitter Matt Harbison
Date Dec. 18, 2018, 6:56 a.m.
Message ID <f8c0ef3b994fd0d0f151.1545116167@Envy>
Download mbox | patch
Permalink /patch/37227/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 18, 2018, 6:56 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1545086685 18000
#      Mon Dec 17 17:44:45 2018 -0500
# Node ID f8c0ef3b994fd0d0f15129067fa59ad72d9bdd66
# Parent  647bea1ea422afe8b593acffccbee2f890e23f48
setup: avoid attempting to invoke the system-wide hg.exe on Windows

On Windows, the executable in the current directory gets priority over anything
in $PATH (both for cmd.exe and MSYS).  That means, the former code was launching
the local hg.exe instead of the system-wide one, if it was previously built.  If
that failed, it then fell back to the local hg code, but run through python.exe.

I'm not sure what it is about ef7119cd4965, but that started throwing up a
messagebox that python37.dll couldn't be loaded.  (And indeed, python37 is not
in $PATH by default.)  Invoking the local hg via the current python avoids that.
Yuya Nishihara - Dec. 18, 2018, 11:46 a.m.
On Tue, 18 Dec 2018 01:56:07 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1545086685 18000
> #      Mon Dec 17 17:44:45 2018 -0500
> # Node ID f8c0ef3b994fd0d0f15129067fa59ad72d9bdd66
> # Parent  647bea1ea422afe8b593acffccbee2f890e23f48
> setup: avoid attempting to invoke the system-wide hg.exe on Windows

Queued, thanks.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -294,14 +294,17 @@  def findhg():
     hgenv['LANGUAGE'] = 'C'
     hgcmd = ['hg']
     # Run a simple "hg log" command just to see if using hg from the user's
-    # path works and can successfully interact with this repository.
+    # path works and can successfully interact with this repository.  Windows
+    # gives precedence to hg.exe in the current directory, so fall back to the
+    # python invocation of local hg, where pythonXY.dll can always be found.
     check_cmd = ['log', '-r.', '-Ttest']
-    try:
-        retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
-    except EnvironmentError:
-        retcode = -1
-    if retcode == 0 and not filterhgerr(err):
-        return hgcommand(hgcmd, hgenv)
+    if os.name != 'nt':
+        try:
+            retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
+        except EnvironmentError:
+            retcode = -1
+        if retcode == 0 and not filterhgerr(err):
+            return hgcommand(hgcmd, hgenv)
 
     # Fall back to trying the local hg installation.
     hgenv = localhgenv()