diff -r 18c8c18993f0 -r 6408777c8fa4 setup.py --- 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