From 2c1c9465d5e4f87a8061ae30431fd87ec42173c6 Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Fri, 16 Sep 2022 11:12:15 +0100 Subject: [PATCH] environment update from .cmd --- update_to_latest.cmd | 61 -------------------------------------------- webui-streamlit.cmd | 57 ++++++++++++++++++++++++----------------- webui.cmd | 57 ++++++++++++++++++++++++----------------- 3 files changed, 68 insertions(+), 107 deletions(-) delete mode 100644 update_to_latest.cmd diff --git a/update_to_latest.cmd b/update_to_latest.cmd deleted file mode 100644 index 1fdfdeb..0000000 --- a/update_to_latest.cmd +++ /dev/null @@ -1,61 +0,0 @@ -@echo off -cd %~dp0 - -:: Duplicate code to find miniconda - -IF EXIST custom-conda-path.txt ( - FOR /F %%i IN (custom-conda-path.txt) DO set v_custom_path=%%i -) - -set v_paths=%ProgramData%\miniconda3 -set v_paths=%v_paths%;%USERPROFILE%\miniconda3 -set v_paths=%v_paths%;%ProgramData%\anaconda3 -set v_paths=%v_paths%;%USERPROFILE%\anaconda3 - -for %%a in (%v_paths%) do ( - IF NOT "%v_custom_path%"=="" ( - set v_paths=%v_custom_path%;%v_paths% - ) -) - -for %%a in (%v_paths%) do ( - if EXIST "%%a\Scripts\activate.bat" ( - SET v_conda_path=%%a - echo anaconda3/miniconda3 detected in %%a - ) -) - -IF "%v_conda_path%"=="" ( - echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html - pause - exit /b 1 -) - -:: Update - -echo Stashing local changes and pulling latest update... -call git stash -call git pull -set /P restore="Do you want to restore changes you made before updating? (Y/N): " -IF /I "%restore%" == "N" ( - echo Removing changes please wait... - call git stash drop - echo Changes removed, press any key to continue... - pause >nul -) ELSE IF /I "%restore%" == "Y" ( - echo Restoring changes, please wait... - call git stash pop --quiet - echo Changes restored, press any key to continue... - pause >nul -) - -for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a -echo %v_cur_hash%>z_version_env.tmp - -call conda env create --name "%v_conda_env_name%" -f environment.yaml -call conda env update --name "%v_conda_env_name%" -f environment.yaml -if not defined AUTO pause - -call "%v_conda_path%\Scripts\activate.bat" - -::cmd /k diff --git a/webui-streamlit.cmd b/webui-streamlit.cmd index eefd2e7..92b1dfc 100644 --- a/webui-streamlit.cmd +++ b/webui-streamlit.cmd @@ -43,33 +43,42 @@ IF "%v_conda_path%"=="" ( ) :CONDA_FOUND - -if not exist "z_version_env.tmp" ( - :: first time running, we need to update - set AUTO=1 - call "update_to_latest.cmd" +echo Stashing local changes and pulling latest update... +call git stash +call git pull +set /P restore="Do you want to restore changes you made before updating? (Y/N): " +IF /I "%restore%" == "N" ( + echo Removing changes please wait... + call git stash drop + echo Changes removed, press any key to continue... + pause >nul +) ELSE IF /I "%restore%" == "Y" ( + echo Restoring changes, please wait... + call git stash pop --quiet + echo Changes restored, press any key to continue... + pause >nul ) +call "%v_conda_path%\Scripts\activate.bat" + +for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a +set /p "v_last_hash="<"z_version_env.tmp" +echo %v_cur_hash%>z_version_env.tmp + +echo Current environment.yaml hash: %v_cur_hash% +echo Previous environment.yaml hash: %v_last_hash% + +if "%v_last_hash%" == "%v_cur_hash%" ( + echo environment.yaml unchanged. dependencies should be up to date. + echo if you still have unresolved dependencies, delete "z_version_env.tmp" +) else ( + echo environment.yaml changed. updating dependencies + call conda env create --name "%v_conda_env_name%" -f environment.yaml + call conda env update --name "%v_conda_env_name%" -f environment.yaml +) + call "%v_conda_path%\Scripts\activate.bat" "%v_conda_env_name%" -set v_last_hash=0 -set /p "v_last_hash="<"z_version_env.tmp" -for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a - -if not "%v_last_hash%" == "%v_cur_hash%" ( - set /P updateenv="Do you want to update with the latest environment.yaml? (Y/N): " - if /I "%updateenv%" == "N" ( - echo Starting without updating dependencies. - ) else if /I "%updateenv%" == "Y" ( - echo Updating dependencies... - call conda env create --name "%v_conda_env_name%" -f environment.yaml - call conda env update --name "%v_conda_env_name%" -f environment.yaml - echo %v_cur_hash%>z_version_env.tmp - ) -) else ( - echo No environment.yaml update required. -) - :PROMPT set SETUPTOOLS_USE_DISTUTILS=stdlib IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" ( @@ -78,3 +87,5 @@ IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" ( echo Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'. pause ) + +::cmd /k diff --git a/webui.cmd b/webui.cmd index dae03a7..97df705 100644 --- a/webui.cmd +++ b/webui.cmd @@ -43,33 +43,42 @@ IF "%v_conda_path%"=="" ( ) :CONDA_FOUND - -if not exist "z_version_env.tmp" ( - :: first time running, we need to update - set AUTO=1 - call "update_to_latest.cmd" +echo Stashing local changes and pulling latest update... +call git stash +call git pull +set /P restore="Do you want to restore changes you made before updating? (Y/N): " +IF /I "%restore%" == "N" ( + echo Removing changes please wait... + call git stash drop + echo Changes removed, press any key to continue... + pause >nul +) ELSE IF /I "%restore%" == "Y" ( + echo Restoring changes, please wait... + call git stash pop --quiet + echo Changes restored, press any key to continue... + pause >nul ) +call "%v_conda_path%\Scripts\activate.bat" + +for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a +set /p "v_last_hash="<"z_version_env.tmp" +echo %v_cur_hash%>z_version_env.tmp + +echo Current environment.yaml hash: %v_cur_hash% +echo Previous environment.yaml hash: %v_last_hash% + +if "%v_last_hash%" == "%v_cur_hash%" ( + echo environment.yaml unchanged. dependencies should be up to date. + echo if you still have unresolved dependencies, delete "z_version_env.tmp" +) else ( + echo environment.yaml changed. updating dependencies + call conda env create --name "%v_conda_env_name%" -f environment.yaml + call conda env update --name "%v_conda_env_name%" -f environment.yaml +) + call "%v_conda_path%\Scripts\activate.bat" "%v_conda_env_name%" -set v_last_hash=0 -set /p "v_last_hash="<"z_version_env.tmp" -for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a - -if not "%v_last_hash%" == "%v_cur_hash%" ( - set /P updateenv="Do you want to update with the latest environment.yaml? (Y/N): " - if /I "%updateenv%" == "N" ( - echo Starting without updating dependencies. - ) else if /I "%updateenv%" == "Y" ( - echo Updating dependencies... - call conda env create --name "%v_conda_env_name%" -f environment.yaml - call conda env update --name "%v_conda_env_name%" -f environment.yaml - echo %v_cur_hash%>z_version_env.tmp - ) -) else ( - echo No environment.yaml update required. -) - :PROMPT set SETUPTOOLS_USE_DISTUTILS=stdlib IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" ( @@ -79,3 +88,5 @@ IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" ( echo Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'. pause ) + +::cmd /k