# HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1729855106 -7200 # Fri Oct 25 13:18:26 2024 +0200 # Node ID d2b826ef74de47b4efce028f525be8a1f1baa0bb # Parent b1439b425248bf3e5e481027281fddca74b52055 # EXP-Topic clean-setup.py setup_py: remove dead code diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# This is the mercurial setup script. +"""This is the mercurial setup script.""" import os import sys @@ -6,7 +6,6 @@ import ctypes import stat import subprocess -import time import re import shutil import tempfile @@ -158,130 +157,6 @@ return p.returncode, out, err -class hgcommand: - def __init__(self, cmd, env): - self.cmd = cmd - self.env = env - - def __repr__(self): - return f"<hgcommand cmd={self.cmd} env={self.env}>" - - def run(self, args): - cmd = self.cmd + args - returncode, out, err = runcmd(cmd, self.env) - err = filterhgerr(err) - if err: - print("stderr from '%s':" % (' '.join(cmd)), file=sys.stderr) - print(err, file=sys.stderr) - if returncode != 0: - print( - "non zero-return '%s': %d" % (' '.join(cmd), returncode), - file=sys.stderr, - ) - return b'' - return out - - -def filterhgerr(err): - # If root is executing setup.py, but the repository is owned by - # another user (as in "sudo python setup.py install") we will get - # trust warnings since the .hg/hgrc file is untrusted. That is - # fine, we don't want to load it anyway. Python may warn about - # a missing __init__.py in mercurial/locale, we also ignore that. - err = [ - e - for e in err.splitlines() - if ( - not e.startswith(b'not trusting file') - and not e.startswith(b'warning: Not importing') - and not ( - e.startswith(b'obsolete feature not enabled') - or e.startswith(b'"obsolete" feature not enabled') - ) - and not e.startswith(b'*** failed to import extension') - and not e.startswith(b'devel-warn:') - and not ( - e.startswith(b'(third party extension') - and e.endswith(b'or newer of Mercurial; disabling)') - ) - ) - ] - return b'\n'.join(b' ' + e for e in err) - - -def findhg(): - """Try to figure out how we should invoke hg for examining the local - repository contents. - - Returns an hgcommand object.""" - # By default, prefer the "hg" command in the user's path. This was - # presumably the hg command that the user used to create this repository. - # - # This repository may require extensions or other settings that would not - # be enabled by running the hg script directly from this local repository. - hgenv = os.environ.copy() - # Use HGPLAIN to disable hgrc settings that would change output formatting, - # and disable localization for the same reasons. - hgenv['HGPLAIN'] = '1' - hgenv['LANGUAGE'] = 'C' - - # PYTHONPATH and co can be used for isolated builds, which can break hg - for key in ["PYTHONPATH", "PYTHONNOUSERSITE"]: - hgenv.pop(key, None) - - 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. 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'] - attempts = [] - - def attempt(cmd, env): - try: - retcode, out, err = runcmd(hgcmd + check_cmd, hgenv) - 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 (pure python) - repo_hg = os.path.join(os.path.dirname(__file__), 'hg') - hgenv = localhgenv() - hgcmd = [sys.executable, repo_hg] - if attempt(hgcmd + check_cmd, hgenv): - return hgcommand(hgcmd, hgenv) - # Fall back to trying the local hg installation (whatever we can) - hgenv = localhgenv(pure_python=False) - hgcmd = [sys.executable, repo_hg] - 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 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 - - def localhgenv(pure_python=True): """Get an environment dictionary to use for invoking or importing mercurial from the local repository."""