modify gui.sh to validate requirements and apply args

This commit is contained in:
zrma 2023-03-19 16:29:16 +09:00
parent 00f74d271a
commit 6bfdbaf3aa
No known key found for this signature in database
GPG Key ID: A2C3341D71125B2E
3 changed files with 30 additions and 2 deletions

12
gui.sh
View File

@ -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

View File

@ -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)

16
upgrade.sh Executable file
View File

@ -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