setup.py
changeset 50936 6408777c8fa4
parent 50803 609a3b8058c3
parent 50930 5dc7e1907e48
child 50987 727428c7e1fc
--- a/setup.py	Fri Sep 01 00:09:55 2023 +0200
+++ b/setup.py	Wed Sep 06 18:12:27 2023 +0200
@@ -278,28 +278,44 @@
     # 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']
-    if os.name != 'nt' or not os.path.exists("hg.exe"):
+    attempts = []
+
+    def attempt(cmd, env):
         try:
             retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
-        except EnvironmentError:
-            retcode = -1
-        if retcode == 0 and not filterhgerr(err):
+            res = (True, retcode, out, err)
+            if retcode == 0 and not filterhgerr(err):
+                return True
+        except EnvironmentError as e:
+            res = (False, e)
+        attempts.append((cmd, res))
+        return False
+
+    if os.name != 'nt' or not os.path.exists("hg.exe"):
+        if attempt(hgcmd + check_cmd, hgenv):
             return hgcommand(hgcmd, hgenv)
 
     # Fall back to trying the local hg installation.
     hgenv = localhgenv()
     hgcmd = [sys.executable, 'hg']
-    try:
-        retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
-    except EnvironmentError:
-        retcode = -1
-    if retcode == 0 and not filterhgerr(err):
+    if attempt(hgcmd + check_cmd, hgenv):
         return hgcommand(hgcmd, hgenv)
 
     eprint("/!\\")
     eprint(r"/!\ Unable to find a working hg binary")
-    eprint(r"/!\ Version cannot be extract from the repository")
+    eprint(r"/!\ Version cannot be extracted from the repository")
     eprint(r"/!\ Re-run the setup once a first version is built")
+    eprint(r"/!\ Attempts:")
+    for i, e in enumerate(attempts):
+        eprint(r"/!\   attempt #%d:" % (i))
+        eprint(r"/!\     cmd:        ", e[0])
+        res = e[1]
+        if res[0]:
+            eprint(r"/!\     return code:", res[1])
+            eprint("/!\\     std output:\n%s" % (res[2].decode()), end="")
+            eprint("/!\\     std error:\n%s" % (res[3].decode()), end="")
+        else:
+            eprint(r"/!\     exception:  ", res[1])
     return None