276 # Run a simple "hg log" command just to see if using hg from the user's |
276 # Run a simple "hg log" command just to see if using hg from the user's |
277 # path works and can successfully interact with this repository. Windows |
277 # path works and can successfully interact with this repository. Windows |
278 # gives precedence to hg.exe in the current directory, so fall back to the |
278 # gives precedence to hg.exe in the current directory, so fall back to the |
279 # python invocation of local hg, where pythonXY.dll can always be found. |
279 # python invocation of local hg, where pythonXY.dll can always be found. |
280 check_cmd = ['log', '-r.', '-Ttest'] |
280 check_cmd = ['log', '-r.', '-Ttest'] |
281 if os.name != 'nt' or not os.path.exists("hg.exe"): |
281 attempts = [] |
|
282 |
|
283 def attempt(cmd, env): |
282 try: |
284 try: |
283 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv) |
285 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv) |
284 except EnvironmentError: |
286 res = (True, retcode, out, err) |
285 retcode = -1 |
287 if retcode == 0 and not filterhgerr(err): |
286 if retcode == 0 and not filterhgerr(err): |
288 return True |
|
289 except EnvironmentError as e: |
|
290 res = (False, e) |
|
291 attempts.append((cmd, res)) |
|
292 return False |
|
293 |
|
294 if os.name != 'nt' or not os.path.exists("hg.exe"): |
|
295 if attempt(hgcmd + check_cmd, hgenv): |
287 return hgcommand(hgcmd, hgenv) |
296 return hgcommand(hgcmd, hgenv) |
288 |
297 |
289 # Fall back to trying the local hg installation. |
298 # Fall back to trying the local hg installation. |
290 hgenv = localhgenv() |
299 hgenv = localhgenv() |
291 hgcmd = [sys.executable, 'hg'] |
300 hgcmd = [sys.executable, 'hg'] |
292 try: |
301 if attempt(hgcmd + check_cmd, hgenv): |
293 retcode, out, err = runcmd(hgcmd + check_cmd, hgenv) |
|
294 except EnvironmentError: |
|
295 retcode = -1 |
|
296 if retcode == 0 and not filterhgerr(err): |
|
297 return hgcommand(hgcmd, hgenv) |
302 return hgcommand(hgcmd, hgenv) |
298 |
303 |
299 eprint("/!\\") |
304 eprint("/!\\") |
300 eprint(r"/!\ Unable to find a working hg binary") |
305 eprint(r"/!\ Unable to find a working hg binary") |
301 eprint(r"/!\ Version cannot be extract from the repository") |
306 eprint(r"/!\ Version cannot be extracted from the repository") |
302 eprint(r"/!\ Re-run the setup once a first version is built") |
307 eprint(r"/!\ Re-run the setup once a first version is built") |
|
308 eprint(r"/!\ Attempts:") |
|
309 for i, e in enumerate(attempts): |
|
310 eprint(r"/!\ attempt #%d:" % (i)) |
|
311 eprint(r"/!\ cmd: ", e[0]) |
|
312 res = e[1] |
|
313 if res[0]: |
|
314 eprint(r"/!\ return code:", res[1]) |
|
315 eprint("/!\\ std output:\n%s" % (res[2].decode()), end="") |
|
316 eprint("/!\\ std error:\n%s" % (res[3].decode()), end="") |
|
317 else: |
|
318 eprint(r"/!\ exception: ", res[1]) |
303 return None |
319 return None |
304 |
320 |
305 |
321 |
306 def localhgenv(): |
322 def localhgenv(): |
307 """Get an environment dictionary to use for invoking or importing |
323 """Get an environment dictionary to use for invoking or importing |