Skip to content

Commit

Permalink
Better error handling during install/update
Browse files Browse the repository at this point in the history
  • Loading branch information
oobabooga committed Sep 28, 2023
1 parent 85f45ca commit 822ba7f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
14 changes: 8 additions & 6 deletions one_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

flags = f"{' '.join([flag for flag in sys.argv[1:] if flag != '--update'])} {CMD_FLAGS}"


def is_linux():
return sys.platform.startswith("linux")

Expand Down Expand Up @@ -87,12 +88,12 @@ def check_env():
conda_exist = run_cmd("conda", environment=True, capture_output=True).returncode == 0
if not conda_exist:
print("Conda is not installed. Exiting...")
sys.exit()
sys.exit(1)

# Ensure this is a new environment and not the base environment
if os.environ["CONDA_DEFAULT_ENV"] == "base":
print("Create an environment for this project and activate it. Exiting...")
sys.exit()
sys.exit(1)


def clear_cache():
Expand Down Expand Up @@ -126,8 +127,8 @@ def run_cmd(cmd, assert_success=False, environment=False, capture_output=False,

# Assert the command ran successfully
if assert_success and result.returncode != 0:
print("Command '" + cmd + "' failed with exit status code '" + str(result.returncode) + "'. Exiting...")
sys.exit()
print("Command '" + cmd + "' failed with exit status code '" + str(result.returncode) + "'.\n\nExiting now.\nTry running the start/update script again.")
sys.exit(1)

return result

Expand All @@ -138,6 +139,7 @@ def install_webui():
choice = os.environ["GPU_CHOICE"].upper()
print_big_message(f"Selected GPU choice \"{choice}\" based on the GPU_CHOICE environment variable.")
else:
print()
print("What is your GPU?")
print()
print("A) NVIDIA")
Expand Down Expand Up @@ -166,7 +168,7 @@ def install_webui():
install_pytorch = "python -m pip install torch==2.0.1+rocm5.4.2 torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.4.2"
else:
print("AMD GPUs are only supported on Linux. Exiting...")
sys.exit()
sys.exit(1)
elif is_linux() and (choice == "C" or choice == "N"):
install_pytorch = "python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu"
elif choice == "D":
Expand Down Expand Up @@ -314,7 +316,7 @@ def launch_webui():
# Check if a model has been downloaded yet
if '--model-dir' in flags:
# Splits on ' ' or '=' while maintaining spaces within quotes
flags_list = re.split(' +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)|=',flags)
flags_list = re.split(' +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)|=', flags)
model_dir = [flags_list[(flags_list.index(flag)+1)] for flag in flags_list if flag == '--model-dir'][0].strip('"\'')
else:
model_dir = 'models'
Expand Down
5 changes: 1 addition & 4 deletions update_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains a
conda activate "$INSTALL_ENV_DIR"

# update installer env
python one_click.py --update

echo
echo "Done!"
python one_click.py --update && echo -e "\nDone!"
5 changes: 1 addition & 4 deletions update_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains a
conda activate "$INSTALL_ENV_DIR"

# update installer env
python one_click.py --update

echo
echo "Done!"
python one_click.py --update && echo -e "\nDone!"
8 changes: 4 additions & 4 deletions update_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ set "CUDA_HOME=%CUDA_PATH%"
call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end )

@rem update installer env
call python one_click.py --update

echo.
echo Done!
call python one_click.py --update && (
echo.
echo Done!
)

:end
pause

0 comments on commit 822ba7f

Please sign in to comment.