diff --git a/Start Stable Diffusion UI.cmd b/Start Stable Diffusion UI.cmd index 20cac347..f5fa3a3c 100644 --- a/Start Stable Diffusion UI.cmd +++ b/Start Stable Diffusion UI.cmd @@ -24,7 +24,6 @@ call git --version call python --version @rem Download the rest of the installer and UI -@REM call installer\install-sd-ui.bat call python installer\installer\main.py pause \ No newline at end of file diff --git a/installer/installer/app.py b/installer/installer/app.py index 5dea5fb9..0bbfd6bf 100644 --- a/installer/installer/app.py +++ b/installer/installer/app.py @@ -3,9 +3,11 @@ import json # config PROJECT_REPO_URL = 'https://github.com/cmdr2/stable-diffusion-ui.git' -DEFAULT_UPDATE_BRANCH = 'installer_new' - +DEFAULT_PROJECT_BRANCH = 'installer_new' PROJECT_REPO_DIR_NAME = 'project_repo' + +STABLE_DIFFUSION_REPO_URL = 'https://github.com/basujindal/stable-diffusion.git' +DEFAULT_STABLE_DIFFUSION_COMMIT = 'f6cfebffa752ee11a7b07497b8529d5971de916c' STABLE_DIFFUSION_REPO_DIR_NAME = 'stable-diffusion' START_CMD_FILE_NAME = os.environ['START_CMD_FILENAME'] diff --git a/installer/installer/main.py b/installer/installer/main.py index e13e1609..b92feb31 100644 --- a/installer/installer/main.py +++ b/installer/installer/main.py @@ -6,11 +6,13 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from installer.tasks import ( fetch_project_repo, apply_project_update, + fetch_stable_diffusion_repo, ) tasks = [ fetch_project_repo, apply_project_update, + fetch_stable_diffusion_repo, ] def run_tasks(): diff --git a/installer/installer/tasks/fetch_project_repo.py b/installer/installer/tasks/fetch_project_repo.py index b920072e..858758bf 100644 --- a/installer/installer/tasks/fetch_project_repo.py +++ b/installer/installer/tasks/fetch_project_repo.py @@ -5,7 +5,7 @@ from installer import app, helpers project_repo_git_path = path.join(app.project_repo_dir_path, '.git') def run(): - branch_name = app.config.get('update_branch', app.DEFAULT_UPDATE_BRANCH) + branch_name = app.config.get('update_branch', app.DEFAULT_PROJECT_BRANCH) if path.exists(project_repo_git_path): helpers.log(f"Stable Diffusion UI's git repository was already installed. Updating from {branch_name}..") @@ -17,8 +17,10 @@ def run(): helpers.log("\nDownloading Stable Diffusion UI..\n") helpers.log(f"Using the {branch_name} channel\n") - if helpers.run(f'git clone -b "{branch_name}" {app.PROJECT_REPO_URL} "{app.project_repo_dir_path}"'): + if helpers.run(f'git clone {app.PROJECT_REPO_URL} "{app.project_repo_dir_path}"'): helpers.log("Downloaded Stable Diffusion UI") else: helpers.show_install_error(error_msg="Could not download Stable Diffusion UI") exit(1) + + helpers.run(f'git checkout "{branch_name}"', run_in_folder=app.project_repo_dir_path) diff --git a/installer/installer/tasks/fetch_stable_diffusion_repo.py b/installer/installer/tasks/fetch_stable_diffusion_repo.py new file mode 100644 index 00000000..5a26aaf4 --- /dev/null +++ b/installer/installer/tasks/fetch_stable_diffusion_repo.py @@ -0,0 +1,46 @@ +from os import path + +from installer import app, helpers + +patch_file_names = [ + 'sd_custom.patch', +] + +stable_diffusion_repo_git_path = path.join(app.stable_diffusion_repo_dir_path, '.git') +patches_dir_path = path.join(app.installer_dir_path, 'patches') + +is_developer_mode = app.config.get('is_developer_mode', False) + +def run(): + fetch_repo() + apply_patches() + +def fetch_repo(): + commit_id = app.config.get('stable_diffusion_commit', app.DEFAULT_STABLE_DIFFUSION_COMMIT) + + if path.exists(stable_diffusion_repo_git_path): + helpers.log(f"Stable Diffusion's git repository was already installed. Using commit: {commit_id}..") + + if not is_developer_mode: + helpers.run("git reset --hard", run_in_folder=app.stable_diffusion_repo_dir_path) + helpers.run(f'git checkout "{commit_id}"', run_in_folder=app.stable_diffusion_repo_dir_path) + helpers.run("git pull", run_in_folder=app.stable_diffusion_repo_dir_path) + else: + helpers.log("\nDownloading Stable Diffusion..\n") + helpers.log(f"Using commit: {commit_id}\n") + + if helpers.run(f'git clone {app.STABLE_DIFFUSION_REPO_URL} "{app.stable_diffusion_repo_dir_path}"'): + helpers.log("Downloaded Stable Diffusion") + else: + helpers.show_install_error(error_msg="Could not download Stable Diffusion") + exit(1) + + helpers.run(f'git checkout "{commit_id}"', run_in_folder=app.stable_diffusion_repo_dir_path) + +def apply_patches(): + if is_developer_mode: + return + + for patch_file_name in patch_file_names: + patch_file_path = path.join(patches_dir_path, patch_file_name) + helpers.run(f"git apply {patch_file_path}", run_in_folder=app.stable_diffusion_repo_dir_path)