aboutsummaryrefslogtreecommitdiff
path: root/launch.py
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-05-11 23:29:34 +0300
committerAarni Koskela <akx@iki.fi>2023-05-12 20:54:06 +0300
commit451d255b5859580c4adf99d67760330d58d76446 (patch)
treebb3195834b3c56e38289d42692ab625b6fb301b1 /launch.py
parent55d222a9f4fb51eeb4c0b0fe4e703d45a39ae7a0 (diff)
Get rid of check_run + run_python
Diffstat (limited to 'launch.py')
-rw-r--r--launch.py21
1 files changed, 8 insertions, 13 deletions
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")