diff --git a/gui.sh b/gui.sh index 90b26db..e4eca6f 100755 --- a/gui.sh +++ b/gui.sh @@ -1,3 +1,13 @@ #!/bin/bash + +# Activate the virtual environment source venv/bin/activate -python kohya_gui.py + +# Validate the requirements and store the exit code +python tools/validate_requirements.py +exit_code=$? + +# If the exit code is 0, run the kohya_gui.py script with the command-line arguments +if [ $exit_code -eq 0 ]; then + python kohya_gui.py "$@" +fi diff --git a/tools/validate_requirements.py b/tools/validate_requirements.py index 9af2ce4..f158bdc 100644 --- a/tools/validate_requirements.py +++ b/tools/validate_requirements.py @@ -1,3 +1,4 @@ +import os import sys import pkg_resources @@ -32,7 +33,8 @@ if missing_requirements or wrong_version_requirements: print("Error: The following packages have the wrong version:") for requirement, expected_version, actual_version in wrong_version_requirements: print(f" - {requirement} (expected version {expected_version}, found version {actual_version})") - print('\nRun \033[33mupgrade.ps1\033[0m or \033[33mpip install -U -r requirements.txt\033[0m to resolve the missing requirements listed above...') + upgrade_script = "upgrade.ps1" if os.name == "nt" else "upgrade.sh" + print(f"\nRun \033[33m{upgrade_script}\033[0m or \033[33mpip install -U -r requirements.txt\033[0m to resolve the missing requirements listed above...") sys.exit(1) diff --git a/upgrade.sh b/upgrade.sh new file mode 100755 index 0000000..f01e7b7 --- /dev/null +++ b/upgrade.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Check if there are any changes that need to be committed +if [[ -n $(git status --short) ]]; then + echo "There are changes that need to be committed. Please stash or undo your changes before running this script." >&2 + exit 1 +fi + +# Pull the latest changes from the remote repository +git pull + +# Activate the virtual environment +source venv/bin/activate + +# Upgrade the required packages +pip install --upgrade -r requirements.txt