import install import subprocess import os import sys import importlib.util python = sys.executable git = os.environ.get("GIT", "git") index_url = os.environ.get("INDEX_URL", "") skip_install = False def run(command, desc=None, errdesc=None, custom_env=None): if desc is not None: print(desc) result = subprocess.run( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env, ) if result.returncode != 0: message = f"""{errdesc or 'Error running command'}. Command: {command} Error code: {result.returncode} stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else ''} stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else ''} """ raise RuntimeError(message) return result.stdout.decode(encoding="utf8", errors="ignore") def check_run(command): result = subprocess.run( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True ) return result.returncode == 0 def is_installed(package): try: spec = importlib.util.find_spec(package) except ModuleNotFoundError: return False return spec is not None def run_pip(args, desc=None): if skip_install: return index_url_line = f" --index-url {index_url}" if index_url != "" else "" return run( f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", ) def run_python(code, desc=None, errdesc=None): return run(f'"{python}" -c "{code}"', desc, errdesc) def extract_arg(args, name): return [x for x in args if x != name], name in args if __name__ == "__main__": install.prepare_environment() from scripts import main main.launch()