Improve setup. Add --headless option

pull/2085/head
bmaltais 2024-03-12 20:31:22 -04:00
parent 890e521b1b
commit b27d0694c4
8 changed files with 99 additions and 151 deletions

View File

@ -21,10 +21,6 @@ fi
echo "Activating venv..."
source "$SCRIPT_DIR/venv/bin/activate" || exit 1
# Install packaging
echo "Installing the python packaging module..."
pip install packaging
# Run setup_linux.py script with platform requirements
echo "Running setup_linux.py..."
python "$SCRIPT_DIR/setup/setup_linux.py" --platform-requirements-file=requirements_runpod.txt --show_stdout --no_run_accelerate

View File

@ -1,13 +1,5 @@
@echo off
set PYTHON_VER=3.10.9
:: Check if Python version meets the recommended version
python --version 2>nul | findstr /b /c:"Python %PYTHON_VER%" >nul
if errorlevel 1 (
echo Warning: Python version %PYTHON_VER% is required. Kohya_ss GUI will most likely fail to run.
)
IF NOT EXIST venv (
echo Creating venv...
python -m venv venv
@ -16,24 +8,18 @@ IF NOT EXIST venv (
:: Create the directory if it doesn't exist
mkdir ".\logs\setup" > nul 2>&1
:: Deactivate the virtual environment
:: Deactivate the virtual environment to prevent error
call .\venv\Scripts\deactivate.bat
:: Calling external python program to check for local modules
:: python .\setup\check_local_modules.py
call .\venv\Scripts\activate.bat
echo "Installing packaging python module..."
pip install packaging
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 python .\setup\setup_windows.py
) ELSE (
REM echo This script was started from a command prompt.
python .\setup\setup_windows.py
python .\setup\setup_windows.py %*
)
:: Deactivate the virtual environment

View File

@ -1,10 +1,3 @@
# Check if Python version meets the recommended version
$pythonVersion = & .\venv\Scripts\python.exe --version 2>$null
if ($pythonVersion -notmatch "^Python $PYTHON_VER") {
Write-Host "Warning: Python version $PYTHON_VER is recommended."
}
if (-not (Test-Path -Path "venv")) {
Write-Host "Creating venv..."
python -m venv venv
@ -16,15 +9,9 @@ $null = New-Item -ItemType Directory -Force -Path ".\logs\setup"
# Deactivate the virtual environment
& .\venv\Scripts\deactivate.bat
# Calling external python program to check for local modules
# & .\venv\Scripts\python.exe .\setup\check_local_modules.py
& .\venv\Scripts\activate.bat
Write-Host "Installing python packaging module..."
& pip install packaging
& .\venv\Scripts\python.exe .\setup\setup_windows.py
& .\venv\Scripts\python.exe .\setup\setup_windows.py $args
# Deactivate the virtual environment
& .\venv\Scripts\deactivate.bat

View File

@ -201,10 +201,6 @@ install_python_dependencies() {
source "$DIR/venv/bin/activate"
fi
# Install packaging
echo "Installing the python packaging module..."
pip install packaging
case "$OSTYPE" in
"lin"*)
if [ "$RUNPOD" = true ]; then

View File

@ -2,16 +2,11 @@ import subprocess
import os
import re
import sys
import filecmp
import logging
import shutil
import sysconfig
import datetime
import platform
import pkg_resources
from packaging import version
errors = 0 # Define the 'errors' variable before using it
log = logging.getLogger('sd')
@ -25,6 +20,8 @@ def check_python_version():
min_version = (3, 10, 9)
max_version = (3, 11, 0)
from packaging import version
try:
current_version = sys.version_info
log.info(f"Python version is {sys.version}")
@ -585,41 +582,18 @@ def ensure_base_requirements():
except ImportError:
install('--upgrade rich', 'rich')
try:
import packaging
except ImportError:
install('packaging')
def run_cmd(run_cmd):
try:
subprocess.run(run_cmd, shell=True, check=False, env=os.environ)
except subprocess.CalledProcessError as e:
print(f'Error occurred while running command: {run_cmd}')
print(f'Error: {e}')
# check python version
def check_python(ignore=True, skip_git=False):
#
# This function was adapted from code written by vladimandic: https://github.com/vladmandic/automatic/commits/master
#
supported_minors = [9, 10]
log.info(f'Python {platform.python_version()} on {platform.system()}')
if not (
int(sys.version_info.major) == 3
and int(sys.version_info.minor) in supported_minors
):
log.error(
f'Incompatible Python version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} required 3.{supported_minors}'
)
if not ignore:
sys.exit(1)
if not skip_git:
git_cmd = os.environ.get('GIT', 'git')
if shutil.which(git_cmd) is None:
log.error('Git not found')
if not ignore:
sys.exit(1)
else:
git_version = git('--version', folder=None, ignore=False)
log.debug(f'Git {git_version.replace("git version", "").strip()}')
log.error(f'Error occurred while running command: {run_cmd}')
log.error(f'Error: {e}')
def delete_file(file_path):

View File

@ -15,7 +15,7 @@ def main_menu(platform_requirements_file, show_stdout: bool = False, no_run_acce
log.info("If this operation ever runs too long, you can rerun this script in verbose mode to check.")
setup_common.check_repo_version()
setup_common.check_python()
# setup_common.check_python()
# Upgrade pip if needed
setup_common.install('pip')

View File

@ -50,7 +50,7 @@ def main_menu(platform_requirements_file):
log.info("If this operation ever runs too long, you can rerun this script in verbose mode to check.")
setup_common.check_repo_version()
setup_common.check_python()
# setup_common.check_python()
# Upgrade pip if needed
setup_common.install('pip')

View File

@ -5,6 +5,7 @@ import logging
import shutil
import sysconfig
import setup_common
import argparse
errors = 0 # Define the 'errors' variable before using it
log = logging.getLogger("sd")
@ -105,9 +106,9 @@ def sync_bits_and_bytes_files():
log.error(f"An unexpected error occurred: {e}")
def install_kohya_ss_torch2():
def install_kohya_ss_torch2(headless: bool = False):
setup_common.check_repo_version()
setup_common.check_python()
setup_common.check_python_version()
setup_common.update_submodule()
@ -118,12 +119,9 @@ def install_kohya_ss_torch2():
"requirements_windows_torch2.txt", check_no_verify_flag=False
)
# sync_bits_and_bytes_files()
if not headless:
setup_common.configure_accelerate(run_accelerate=True)
# run_cmd(f'accelerate config')
def install_bitsandbytes_0_35_0():
log.info("Installing bitsandbytes 0.35.0...")
@ -158,7 +156,12 @@ def install_bitsandbytes_0_41_2():
reinstall=True,
)
def main_menu():
def main_menu(headless: bool = False):
setup_common.ensure_base_requirements()
if headless:
install_kohya_ss_torch2(headless=headless)
else:
setup_common.clear_screen()
while True:
print("\nKohya_ss GUI setup menu:\n")
@ -230,7 +233,13 @@ def main_menu():
if __name__ == "__main__":
python_ver = setup_common.check_python_version()
setup_common.ensure_base_requirements()
setup_common.setup_logging()
main_menu()
# Setup argument parser
parser = argparse.ArgumentParser(description="Your Script Description")
parser.add_argument('--headless', action='store_true', help='Run in headless mode')
# Parse arguments
args = parser.parse_args()
main_menu(headless=args.headless)