From 49db24ce273ebccb598fc13de946d1ac3cad38f8 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:30:29 +0300 Subject: launch.py: Add debugging envvar to see install output --- launch.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index cfc0cffa..136e8855 100644 --- a/launch.py +++ b/launch.py @@ -22,6 +22,9 @@ stored_commit_hash = None stored_git_tag = None dir_repos = "repositories" +# Whether to default to printing command output +default_command_live = (os.environ.get('WEBUI_LAUNCH_LIVE_OUTPUT') == "1") + if 'GRADIO_ANALYTICS_ENABLED' not in os.environ: os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False' @@ -85,7 +88,7 @@ def git_tag(): return stored_git_tag -def run(command, desc=None, errdesc=None, custom_env=None, live=False): +def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live): if desc is not None: print(desc) @@ -135,7 +138,7 @@ def run_python(code, desc=None, errdesc=None): return run(f'"{python}" -c "{code}"', desc, errdesc) -def run_pip(command, desc=None, live=False): +def run_pip(command, desc=None, live=default_command_live): if args.skip_install: return -- cgit v1.2.3 From 875bc270093b4f89b9d0d20a93a5e8ea514b3f6c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:34:19 +0300 Subject: launch.py: Simplify run() --- launch.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 136e8855..ae75f6fd 100644 --- a/launch.py +++ b/launch.py @@ -88,32 +88,36 @@ def git_tag(): return stored_git_tag -def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live): +def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live) -> str: if desc is not None: print(desc) - if live: - result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env) - if result.returncode != 0: - raise RuntimeError(f"""{errdesc or 'Error running command'}. -Command: {command} -Error code: {result.returncode}""") + run_kwargs = { + "args": command, + "shell": True, + "env": os.environ if custom_env is None else custom_env, + "encoding": 'utf8', + "errors": 'ignore', + } - return "" + if not live: + run_kwargs["stdout"] = run_kwargs["stderr"] = subprocess.PIPE - result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env) + result = subprocess.run(**run_kwargs) 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") + error_bits = [ + f"{errdesc or 'Error running command'}.", + f"Command: {command}", + f"Error code: {result.returncode}", + ] + if result.stdout: + error_bits.append(f"stdout: {result.stdout}") + if result.stderr: + error_bits.append(f"stderr: {result.stderr}") + raise RuntimeError("\n".join(error_bits)) + + return (result.stdout or "") def check_run(command): -- cgit v1.2.3 From a09e1e6e18e800191817493253dfc481a07b1868 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:48:48 +0300 Subject: launch.py: Use GitHub archive URLs for gfpgan, clip, openclip instead of git clones --- launch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index ae75f6fd..fed14d93 100644 --- a/launch.py +++ b/launch.py @@ -248,9 +248,9 @@ def prepare_environment(): requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') - gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379") - clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1") - openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b") + gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "https://github.com/TencentARC/GFPGAN/archive/8d2447a2d918f8eba5a4a01463fd48e45126a379.zip") + clip_package = os.environ.get('CLIP_PACKAGE', "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip") + openclip_package = os.environ.get('OPENCLIP_PACKAGE', "https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip") stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/Stability-AI/stablediffusion.git") taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git") -- cgit v1.2.3 From dd3ca9adf7077cb7209b31fd16a40deffc4948ca Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:35:22 +0300 Subject: launch.py: make torch_index_url an envvar --- launch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index fed14d93..670af87c 100644 --- a/launch.py +++ b/launch.py @@ -244,7 +244,8 @@ def run_extensions_installers(settings_file): def prepare_environment(): - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118") + torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118") + torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') -- cgit v1.2.3 From 49a55b410b66b7dd9be9335d8a2e3a71e4f8b15c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 18:28:15 +0300 Subject: Autofix Ruff W (not W605) (mostly whitespace) --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 670af87c..62b33f14 100644 --- a/launch.py +++ b/launch.py @@ -327,7 +327,7 @@ def prepare_environment(): if args.update_all_extensions: git_pull_recursive(extensions_dir) - + if "--exit" in sys.argv: print("Exiting because of --exit argument") exit(0) -- cgit v1.2.3 From 681c16dd1e911bdf831b031b0f31aaba41c280f8 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 12 May 2023 22:33:21 +0900 Subject: fix --data-dir for COMMANDLINE_ARGS move reading of COMMANDLINE_ARGS into paths_internal.py so --data-dir can be properly read --- launch.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 62b33f14..516746ac 100644 --- a/launch.py +++ b/launch.py @@ -3,16 +3,12 @@ import subprocess import os import sys import importlib.util -import shlex import platform import json from modules import cmd_args from modules.paths_internal import script_path, extensions_dir -commandline_args = os.environ.get('COMMANDLINE_ARGS', "") -sys.argv += shlex.split(commandline_args) - args, _ = cmd_args.parser.parse_known_args() python = sys.executable -- cgit v1.2.3 From 55d222a9f4fb51eeb4c0b0fe4e703d45a39ae7a0 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 23:00:53 +0300 Subject: launch.py: make git_tag() and commit_hash() work even when WEBUI_LAUNCH_LIVE_OUTPUT --- launch.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 516746ac..ae67fe5c 100644 --- a/launch.py +++ b/launch.py @@ -5,6 +5,7 @@ import sys import importlib.util import platform import json +from functools import lru_cache from modules import cmd_args from modules.paths_internal import script_path, extensions_dir @@ -14,8 +15,6 @@ args, _ = cmd_args.parser.parse_known_args() python = sys.executable git = os.environ.get('GIT', "git") index_url = os.environ.get('INDEX_URL', "") -stored_commit_hash = None -stored_git_tag = None dir_repos = "repositories" # Whether to default to printing command output @@ -56,32 +55,20 @@ Use --skip-python-version-check to suppress this warning. """) +@lru_cache() def commit_hash(): - global stored_commit_hash - - if stored_commit_hash is not None: - return stored_commit_hash - try: - stored_commit_hash = run(f"{git} rev-parse HEAD").strip() + return subprocess.check_output(f"{git} rev-parse HEAD", encoding='utf8').strip() except Exception: - stored_commit_hash = "" - - return stored_commit_hash + return "" +@lru_cache() def git_tag(): - global stored_git_tag - - if stored_git_tag is not None: - return stored_git_tag - try: - stored_git_tag = run(f"{git} describe --tags").strip() + return subprocess.check_output(f"{git} describe --tags", encoding='utf8').strip() except Exception: - stored_git_tag = "" - - return stored_git_tag + return "" def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live) -> str: -- cgit v1.2.3 From 451d255b5859580c4adf99d67760330d58d76446 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 23:29:34 +0300 Subject: Get rid of check_run + run_python --- launch.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index ae67fe5c..578af229 100644 --- a/launch.py +++ b/launch.py @@ -103,11 +103,6 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_ return (result.stdout or "") -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) @@ -121,10 +116,6 @@ def repo_dir(name): return os.path.join(script_path, dir_repos, name) -def run_python(code, desc=None, errdesc=None): - return run(f'"{python}" -c "{code}"', desc, errdesc) - - def run_pip(command, desc=None, live=default_command_live): if args.skip_install: return @@ -133,8 +124,9 @@ def run_pip(command, desc=None, live=default_command_live): return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live) -def check_run_python(code): - return check_run(f'"{python}" -c "{code}"') +def check_run_python(code: str) -> bool: + result = subprocess.run([python, "-c", code], capture_output=True, shell=True) + return result.returncode == 0 def git_clone(url, dir, name, commithash=None): @@ -261,8 +253,11 @@ def prepare_environment(): if args.reinstall_torch or not is_installed("torch") or not is_installed("torchvision"): run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) - if not args.skip_torch_cuda_test: - run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'") + if not args.skip_torch_cuda_test and not check_run_python("import torch; assert torch.cuda.is_available()"): + raise RuntimeError( + 'Torch is not able to use GPU; ' + 'add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check' + ) if not is_installed("gfpgan"): run_pip(f"install {gfpgan_package}", "gfpgan") -- cgit v1.2.3 From d9968e61082fb5ed16eedfe8fa43bf6f2e7b76e7 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 14 May 2023 20:30:02 +0300 Subject: launch.py: Don't involve shell for running Python or Git for output Fixes Linux regression in 451d255b5859580c4adf99d67760330d58d76446 --- launch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 578af229..f8380911 100644 --- a/launch.py +++ b/launch.py @@ -58,7 +58,7 @@ Use --skip-python-version-check to suppress this warning. @lru_cache() def commit_hash(): try: - return subprocess.check_output(f"{git} rev-parse HEAD", encoding='utf8').strip() + return subprocess.check_output([git, "rev-parse", "HEAD"], shell=False, encoding='utf8').strip() except Exception: return "" @@ -66,7 +66,7 @@ def commit_hash(): @lru_cache() def git_tag(): try: - return subprocess.check_output(f"{git} describe --tags", encoding='utf8').strip() + return subprocess.check_output([git, "describe", "--tags"], shell=False, encoding='utf8').strip() except Exception: return "" @@ -125,7 +125,7 @@ def run_pip(command, desc=None, live=default_command_live): def check_run_python(code: str) -> bool: - result = subprocess.run([python, "-c", code], capture_output=True, shell=True) + result = subprocess.run([python, "-c", code], capture_output=True, shell=False) return result.returncode == 0 -- cgit v1.2.3