fix: launcher batch file fix #920, fix #605

- Allow reading environment.yaml file in either LF or CRLF
- Only update environment if environment.yaml changes
- Remove custom_conda_path to discourage changing source file
- Fix unable to launch webui due to frontend module missing (#605)
This commit is contained in:
Syahmi Azhar 2022-09-13 17:13:23 +08:00 committed by GitHub
parent 63407de224
commit 93d53f9c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 63 deletions

1
.gitignore vendored
View File

@ -64,3 +64,4 @@ condaenv.*.requirements.txt
/flagged/*
/gfpgan/*
/models/custom/
/z_version_env.tmp

View File

@ -4,58 +4,71 @@
cd %~dp0
:: copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
set /p first_line=< environment.yaml
for /f "tokens=2 delims=:" %%i in ("%first_line%") do set untrimmed_conda_env_name=%%i
for /f "tokens=* delims= " %%a in ("%untrimmed_conda_env_name%") do set conda_env_name=%%a
echo Environment name is set as %conda_env_name% as per environment.yaml
:: Put the path to conda directory after "=" sign if it's installed at non-standard path:
set custom_conda_path=
IF NOT "%custom_conda_path%"=="" (
set paths=%custom_conda_path%;%paths%
for /F "tokens=2 delims=: " %%i in (environment.yaml) DO (
set v_conda_env_name=%%i
goto EOL
)
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path:
FOR /F %%i IN (custom-conda-path.txt) DO set custom_conda_path=%%i
:EOL
set paths=%ProgramData%\miniconda3
set paths=%paths%;%USERPROFILE%\miniconda3
set paths=%paths%;%ProgramData%\anaconda3
set paths=%paths%;%USERPROFILE%\anaconda3
echo Environment name is set as %v_conda_env_name% as per environment.yaml
for %%a in (%paths%) do (
IF NOT "%custom_conda_path%"=="" (
set paths=%custom_conda_path%;%paths%
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path
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 (%paths%) do (
for %%a in (%v_paths%) do (
if EXIST "%%a\Scripts\activate.bat" (
SET CONDA_PATH=%%a
SET v_conda_path=%%a
echo anaconda3/miniconda3 detected in %%a
goto :foundPath
goto :CONDA_FOUND
)
)
IF "%CONDA_PATH%"=="" (
IF "%v_conda_path%"=="" (
echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html
exit /b 1
)
:CONDA_FOUND
echo Stashing local changes and pulling latest update...
call git stash
call git pull
call "%v_conda_path%\Scripts\activate.bat"
:foundPath
call "%CONDA_PATH%\Scripts\activate.bat"
call conda env create -n "%conda_env_name%" -f environment.yaml
call conda env update --name "%conda_env_name%" -f environment.yaml
call "%CONDA_PATH%\Scripts\activate.bat" "%conda_env_name%"
::python "%CD%"\scripts\relauncher.py
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 version doesn't change
) 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%"
:PROMPT
set SETUPTOOLS_USE_DISTUTILS=stdlib
IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" (
python -m streamlit run scripts\webui_streamlit.py --theme.base dark
) ELSE (
ECHO Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
echo Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
pause
)

View File

@ -4,58 +4,72 @@
cd %~dp0
:: copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
set /p first_line=< environment.yaml
for /f "tokens=2 delims=:" %%i in ("%first_line%") do set untrimmed_conda_env_name=%%i
for /f "tokens=* delims= " %%a in ("%untrimmed_conda_env_name%") do set conda_env_name=%%a
echo Environment name is set as %conda_env_name% as per environment.yaml
:: Put the path to conda directory after "=" sign if it's installed at non-standard path:
set custom_conda_path=
IF NOT "%custom_conda_path%"=="" (
set paths=%custom_conda_path%;%paths%
for /F "tokens=2 delims=: " %%i in (environment.yaml) DO (
set v_conda_env_name=%%i
goto EOL
)
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path:
FOR /F %%i IN (custom-conda-path.txt) DO set custom_conda_path=%%i
:EOL
set paths=%ProgramData%\miniconda3
set paths=%paths%;%USERPROFILE%\miniconda3
set paths=%paths%;%ProgramData%\anaconda3
set paths=%paths%;%USERPROFILE%\anaconda3
echo Environment name is set as %v_conda_env_name% as per environment.yaml
for %%a in (%paths%) do (
IF NOT "%custom_conda_path%"=="" (
set paths=%custom_conda_path%;%paths%
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path
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 (%paths%) do (
for %%a in (%v_paths%) do (
if EXIST "%%a\Scripts\activate.bat" (
SET CONDA_PATH=%%a
SET v_conda_path=%%a
echo anaconda3/miniconda3 detected in %%a
goto :foundPath
goto :CONDA_FOUND
)
)
IF "%CONDA_PATH%"=="" (
IF "%v_conda_path%"=="" (
echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html
exit /b 1
)
:CONDA_FOUND
echo Stashing local changes and pulling latest update...
call git stash
call git pull
call "%v_conda_path%\Scripts\activate.bat"
:foundPath
call "%CONDA_PATH%\Scripts\activate.bat"
call conda env create -n "%conda_env_name%" -f environment.yaml
call conda env update -n "%conda_env_name%" --file environment.yaml --prune
call "%CONDA_PATH%\Scripts\activate.bat" "%conda_env_name%"
python "%CD%"\scripts\relauncher.py
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 version doesn't change
) 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%"
:PROMPT
set SETUPTOOLS_USE_DISTUTILS=stdlib
IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" (
python scripts/relauncher.py
set PYTHONPATH=%~dp0
python scripts\relauncher.py
) ELSE (
ECHO Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
echo Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
pause
)