# HG changeset patch # User Arseniy Alekseyev # Date 1693830812 -3600 # Node ID 5dc7e1907e48b35ebccafe541d885bf0f146328e # Parent 0a4efb650b3efedbce997ee6e05d8487579d41f6 setup: make the error "Unable to find a working hg binary" more informative The error message now shows the attempted hg commands and their stderr, to make it easier to investigate why things are not working. Here's an example output /!\ /!\ Unable to find a working hg binary /!\ Version cannot be extracted from the repository /!\ Re-run the setup once a first version is built /!\ Attempts: /!\ attempt #0: /!\ cmd: ['hg-missing', 'log', '-r.', '-Ttest'] /!\ exception: [Errno 2] No such file or directory: 'hg-missing': 'hg-missing' /!\ attempt #1: /!\ cmd: ['/usr/bin/python3', 'hg', 'log', '-r.', '-Ttest'] /!\ return code: 255 /!\ std output: /!\ std error: *** failed to import extension "topic": No module named 'topic' *** failed to import extension "evolve": No module named 'evolve' abort: accessing `dirstate-v2` repository without associated fast implementation. (check `hg help config.format.use-dirstate-v2` for details) /!\ /!\ Could not determine the Mercurial version /!\ You need to build a local version first /!\ Run `make local` and try again /!\ diff -r 0a4efb650b3e -r 5dc7e1907e48 setup.py --- a/setup.py Mon Aug 21 10:21:58 2023 -0400 +++ b/setup.py Mon Sep 04 13:33:32 2023 +0100 @@ -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