From 59dfe0845d964868e92572c78a420b6d68c46ea4 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 30 Oct 2022 08:22:44 +0300 Subject: launch tests from launch.py with --tests commandline argument --- launch.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 8affd410..33f98343 100644 --- a/launch.py +++ b/launch.py @@ -128,10 +128,12 @@ def prepare_enviroment(): blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9") sys.argv += shlex.split(commandline_args) + test_argv = [x for x in sys.argv if x != '--tests'] sys.argv, skip_torch_cuda_test = extract_arg(sys.argv, '--skip-torch-cuda-test') sys.argv, reinstall_xformers = extract_arg(sys.argv, '--reinstall-xformers') sys.argv, update_check = extract_arg(sys.argv, '--update-check') + sys.argv, run_tests = extract_arg(sys.argv, '--tests') xformers = '--xformers' in sys.argv deepdanbooru = '--deepdanbooru' in sys.argv ngrok = '--ngrok' in sys.argv @@ -194,6 +196,23 @@ def prepare_enviroment(): print("Exiting because of --exit argument") exit(0) + if run_tests: + tests(test_argv) + exit(0) + + +def tests(argv): + print(f"Launching Web UI in another process for testing with arguments: {' '.join(argv[1:])}") + + with open('test/stdout.txt', "w", encoding="utf8") as stdout, open('test/stderr.txt', "w", encoding="utf8") as stderr: + proc = subprocess.Popen([sys.executable, *argv], stdout=stdout, stderr=stderr) + + import test.server_poll + test.server_poll.run_tests() + + print(f"Stopping Web UI process with id {proc.pid}") + proc.kill() + def start_webui(): print(f"Launching Web UI with arguments: {' '.join(sys.argv[1:])}") -- cgit v1.2.3 From 5a6e0cfba675c0f11ade7124cbeec1356c77beb2 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 30 Oct 2022 08:28:36 +0300 Subject: always add --api when running tests --- launch.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 33f98343..958336f2 100644 --- a/launch.py +++ b/launch.py @@ -202,6 +202,9 @@ def prepare_enviroment(): def tests(argv): + if "--api" not in argv: + argv.append("--api") + print(f"Launching Web UI in another process for testing with arguments: {' '.join(argv[1:])}") with open('test/stdout.txt', "w", encoding="utf8") as stdout, open('test/stderr.txt', "w", encoding="utf8") as stderr: -- cgit v1.2.3 From d35bf649456da2558cbb6f2ea16fa1606022b7e7 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 1 Nov 2022 14:19:24 +0300 Subject: make launch.py run installers for extensions that have ones add some more classes to safety module for an extension --- launch.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 958336f2..0d90d553 100644 --- a/launch.py +++ b/launch.py @@ -7,6 +7,7 @@ import shlex import platform dir_repos = "repositories" +dir_extensions = "extensions" python = sys.executable git = os.environ.get('GIT', "git") index_url = os.environ.get('INDEX_URL', "") @@ -101,9 +102,24 @@ def version_check(commit): else: print("Not a git clone, can't perform version check.") except Exception as e: - print("versipm check failed",e) + print("version check failed", e) + + +def run_extensions_installers(): + if not os.path.isdir(dir_extensions): + return + + for dirname_extension in os.listdir(dir_extensions): + path_installer = os.path.join(dir_extensions, dirname_extension, "install.py") + if not os.path.isfile(path_installer): + continue + + try: + print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {dirname_extension}")) + except Exception as e: + print(e, file=sys.stderr) + - def prepare_enviroment(): torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") @@ -189,6 +205,8 @@ def prepare_enviroment(): run_pip(f"install -r {requirements_file}", "requirements for Web UI") + run_extensions_installers() + if update_check: version_check(commit) -- cgit v1.2.3 From b85e83c3bd869c3f1ffacf8d3ff97bd9d406acff Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 1 Nov 2022 14:48:53 +0300 Subject: add PYTHONPATH for extension's install.py --- launch.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 0d90d553..ff2f74ba 100644 --- a/launch.py +++ b/launch.py @@ -17,11 +17,11 @@ def extract_arg(args, name): return [x for x in args if x != name], name in args -def run(command, desc=None, errdesc=None): +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) + 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: @@ -115,7 +115,10 @@ def run_extensions_installers(): continue try: - print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {dirname_extension}")) + env = os.environ.copy() + env['PYTHONPATH'] = os.path.abspath(".") + + print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {dirname_extension}", custom_env=env)) except Exception as e: print(e, file=sys.stderr) -- cgit v1.2.3