mirror of https://github.com/bmaltais/kohya_ss
Refactor: Improve gui-uv.bat and gui-uv.sh scripts
This commit introduces several improvements to the UV-based GUI launcher scripts for both Windows (`gui-uv.bat`) and Linux/macOS (`gui-uv.sh`):
- Explicit Virtual Environment Creation: Both scripts now explicitly ensure the `.venv` virtual environment is created/updated using `uv venv .venv`.
- Consistent Argument Handling: Added `--quiet` argument support to `gui-uv.bat` to match `gui-uv.sh`.
- Enhanced Error Handling:
- Both scripts now provide clearer error messages and exit if `git submodule update` fails.
- `gui-uv.sh` now uses `set -e` for more robust error checking.
- Improved Readability: Added comments to clarify complex sections of the scripts, such as Windows double-click detection and WSL/sudo `LD_LIBRARY_PATH` management in the shell script.
- PyTorch Path: Clarified the purpose of the PyTorch DLL path modification in `gui-uv.bat` with a comment.
The `--index-strategy unsafe-best-match` in `gui-uv.bat` and the `--noverify` flag in both scripts have been retained as per existing functionality.
improve-gui-uv-scripts
parent
23b70c8f16
commit
32fe45d282
30
gui-uv.bat
30
gui-uv.bat
|
|
@ -16,21 +16,41 @@ if %errorlevel% neq 0 (
|
|||
)
|
||||
endlocal
|
||||
|
||||
echo Ensuring virtual environment .venv is set up...
|
||||
uv venv .venv
|
||||
if errorlevel 1 (
|
||||
echo Failed to create or set up the virtual environment. Exiting.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: Ensures PyTorch native libraries (DLLs) are found
|
||||
set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib
|
||||
|
||||
echo Starting the GUI... this might take some time... Especially on 1st run after install or update...
|
||||
|
||||
:: Make sure we are on the right sd-scripts commit
|
||||
git submodule update --init --recursive
|
||||
if errorlevel 1 (
|
||||
echo Error updating git submodules. Please check for errors and try again.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: If the exit code is 0, run the kohya_gui.py script with the command-line arguments
|
||||
if %errorlevel% equ 0 (
|
||||
:: If we reach here, git submodules updated successfully.
|
||||
set "uv_quiet_arg="
|
||||
for %%a in (%*) do (
|
||||
if /i "%%a"=="--quiet" (
|
||||
set "uv_quiet_arg=--quiet"
|
||||
)
|
||||
)
|
||||
|
||||
REM Check if the script was started by double-clicking (interactive session)
|
||||
REM or from an existing command prompt.
|
||||
REM If double-clicked, use 'cmd /k' to keep the window open after uv run finishes or errors.
|
||||
REM Check if the batch was started via double-click
|
||||
IF /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" (
|
||||
REM echo This script was started by double clicking.
|
||||
cmd /k uv run --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %*
|
||||
cmd /k uv run %uv_quiet_arg% --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %*
|
||||
) ELSE (
|
||||
REM echo This script was started from a command prompt.
|
||||
uv run --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %*
|
||||
)
|
||||
uv run %uv_quiet_arg% --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %*
|
||||
)
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
export VIRTUAL_ENV=.venv
|
||||
|
||||
env_var_exists() {
|
||||
|
|
@ -9,6 +10,8 @@ env_var_exists() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Handle LD_LIBRARY_PATH for WSL environments and preserve it when using sudo,
|
||||
# as these can affect how shared libraries are found.
|
||||
lib_path="/usr/lib/wsl/lib/"
|
||||
|
||||
if [ -d "$lib_path" ]; then
|
||||
|
|
@ -47,9 +50,12 @@ if ! command -v uv &> /dev/null; then
|
|||
fi
|
||||
fi
|
||||
|
||||
echo "Ensuring virtual environment .venv is set up..."
|
||||
uv venv .venv || { echo "Failed to create or set up the virtual environment. Exiting."; exit 1; }
|
||||
|
||||
if [[ "$uv_quiet" == "--quiet" ]]; then
|
||||
echo "Notice: uv will run in quiet mode. No indication of the uv module download and install process will be displayed."
|
||||
fi
|
||||
|
||||
git submodule update --init --recursive
|
||||
git submodule update --init --recursive || { echo "ERROR: Failed to update git submodules. Please check for errors above and try again." >&2; exit 1; }
|
||||
uv run $uv_quiet kohya_gui.py --noverify "${args[@]}"
|
||||
|
|
|
|||
|
|
@ -54,18 +54,9 @@ dependencies = [
|
|||
]
|
||||
|
||||
[tool.uv.sources]
|
||||
torch = [
|
||||
{ index = "pytorch-cu128", marker = "sys_platform == 'linux'" },
|
||||
{ index = "pytorch-cu128", marker = "sys_platform == 'win32'" }
|
||||
]
|
||||
torchvision = [
|
||||
{ index = "pytorch-cu128", marker = "sys_platform == 'linux'" },
|
||||
{ index = "pytorch-cu128", marker = "sys_platform == 'win32'" }
|
||||
]
|
||||
xformers = [
|
||||
{ index = "pytorch-cu128", marker = "sys_platform == 'linux'" },
|
||||
{ index = "pytorch-cu128", marker = "sys_platform == 'win32'" }
|
||||
]
|
||||
torch = { index = "pytorch-cu128" }
|
||||
torchvision = { index = "pytorch-cu128" }
|
||||
xformers = { index = "pytorch-cu128" }
|
||||
library = { path = "sd-scripts" }
|
||||
|
||||
[[tool.uv.index]]
|
||||
|
|
|
|||
Loading…
Reference in New Issue