Skip to content

Commit a91792e

Browse files
committed
batch: Fix batch file (Sygil-Dev#920, Sygil-Dev#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 (Sygil-Dev#605)
1 parent c63fcb1 commit a91792e

File tree

3 files changed

+87
-59
lines changed

3 files changed

+87
-59
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ condaenv.*.requirements.txt
6464
/flagged/*
6565
/gfpgan/*
6666
/models/custom/
67+
/z_version_env.tmp

webui-streamlit.cmd

+42-29
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,72 @@
33
:: Run all commands using this script's directory as the working directory
44
cd %~dp0
55

6-
:: copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
7-
set /p first_line=< environment.yaml
8-
for /f "tokens=2 delims=:" %%i in ("%first_line%") do set untrimmed_conda_env_name=%%i
9-
for /f "tokens=* delims= " %%a in ("%untrimmed_conda_env_name%") do set conda_env_name=%%a
10-
echo Environment name is set as %conda_env_name% as per environment.yaml
6+
:: copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
7+
for /F "tokens=2 delims=: " %%i in (environment.yaml) DO (
8+
set v_conda_env_name=%%i
9+
goto EOL
10+
)
11+
:EOL
1112

12-
:: Put the path to conda directory after "=" sign if it's installed at non-standard path:
13-
set custom_conda_path=
13+
echo Environment name is set as %v_conda_env_name% as per environment.yaml
1414

15-
IF NOT "%custom_conda_path%"=="" (
16-
set paths=%custom_conda_path%;%paths%
15+
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path
16+
IF EXIST custom-conda-path.txt (
17+
FOR /F %%i IN (custom-conda-path.txt) DO set v_custom_path=%%i
1718
)
18-
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path:
19-
FOR /F %%i IN (custom-conda-path.txt) DO set custom_conda_path=%%i
2019

21-
set paths=%ProgramData%\miniconda3
22-
set paths=%paths%;%USERPROFILE%\miniconda3
23-
set paths=%paths%;%ProgramData%\anaconda3
24-
set paths=%paths%;%USERPROFILE%\anaconda3
20+
set v_paths=%ProgramData%\miniconda3
21+
set v_paths=%v_paths%;%USERPROFILE%\miniconda3
22+
set v_paths=%v_paths%;%ProgramData%\anaconda3
23+
set v_paths=%v_paths%;%USERPROFILE%\anaconda3
2524

26-
for %%a in (%paths%) do (
27-
IF NOT "%custom_conda_path%"=="" (
28-
set paths=%custom_conda_path%;%paths%
25+
for %%a in (%v_paths%) do (
26+
IF NOT "%v_custom_path%"=="" (
27+
set v_paths=%v_custom_path%;%v_paths%
2928
)
3029
)
3130

32-
for %%a in (%paths%) do (
31+
for %%a in (%v_paths%) do (
3332
if EXIST "%%a\Scripts\activate.bat" (
34-
SET CONDA_PATH=%%a
33+
SET v_conda_path=%%a
3534
echo anaconda3/miniconda3 detected in %%a
36-
goto :foundPath
35+
goto :CONDA_FOUND
3736
)
3837
)
3938

40-
IF "%CONDA_PATH%"=="" (
39+
IF "%v_conda_path%"=="" (
4140
echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html
4241
exit /b 1
4342
)
4443

44+
:CONDA_FOUND
45+
echo Stashing local changes and pulling latest update...
4546
call git stash
4647
call git pull
48+
call "%v_conda_path%\Scripts\activate.bat"
49+
50+
for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a
51+
set /p "v_last_hash="<"z_version_env.tmp" 1>NUL 2>&1
52+
echo %v_cur_hash%>z_version_env.tmp
53+
54+
echo Current environment.yaml hash: %v_cur_hash%
55+
echo Previous environment.yaml hash: %v_last_hash%
56+
57+
if "%v_last_hash%" == "%v_cur_hash%" (
58+
echo environment.yaml version doesn't change
59+
) else (
60+
echo environment.yaml changed, updating dependencies
61+
call conda env create --name "%v_conda_env_name%" -f environment.yaml
62+
call conda env update --name "%v_conda_env_name%" -f environment.yaml
63+
)
4764

48-
:foundPath
49-
call "%CONDA_PATH%\Scripts\activate.bat"
50-
call conda env create -n "%conda_env_name%" -f environment.yaml
51-
call conda env update --name "%conda_env_name%" -f environment.yaml
52-
call "%CONDA_PATH%\Scripts\activate.bat" "%conda_env_name%"
53-
::python "%CD%"\scripts\relauncher.py
65+
call "%v_conda_path%\Scripts\activate.bat" "%v_conda_env_name%"
5466

5567
:PROMPT
5668
set SETUPTOOLS_USE_DISTUTILS=stdlib
5769
IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" (
5870
python -m streamlit run scripts\webui_streamlit.py --theme.base dark
5971
) ELSE (
60-
ECHO Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
72+
echo Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
73+
pause
6174
)

webui.cmd

+44-30
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,73 @@
33
:: Run all commands using this script's directory as the working directory
44
cd %~dp0
55

6-
:: copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
7-
set /p first_line=< environment.yaml
8-
for /f "tokens=2 delims=:" %%i in ("%first_line%") do set untrimmed_conda_env_name=%%i
9-
for /f "tokens=* delims= " %%a in ("%untrimmed_conda_env_name%") do set conda_env_name=%%a
10-
echo Environment name is set as %conda_env_name% as per environment.yaml
6+
:: copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
7+
for /F "tokens=2 delims=: " %%i in (environment.yaml) DO (
8+
set v_conda_env_name=%%i
9+
goto EOL
10+
)
11+
:EOL
1112

12-
:: Put the path to conda directory after "=" sign if it's installed at non-standard path:
13-
set custom_conda_path=
13+
echo Environment name is set as %v_conda_env_name% as per environment.yaml
1414

15-
IF NOT "%custom_conda_path%"=="" (
16-
set paths=%custom_conda_path%;%paths%
15+
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path
16+
IF EXIST custom-conda-path.txt (
17+
FOR /F %%i IN (custom-conda-path.txt) DO set v_custom_path=%%i
1718
)
18-
:: Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path:
19-
FOR /F %%i IN (custom-conda-path.txt) DO set custom_conda_path=%%i
2019

21-
set paths=%ProgramData%\miniconda3
22-
set paths=%paths%;%USERPROFILE%\miniconda3
23-
set paths=%paths%;%ProgramData%\anaconda3
24-
set paths=%paths%;%USERPROFILE%\anaconda3
20+
set v_paths=%ProgramData%\miniconda3
21+
set v_paths=%v_paths%;%USERPROFILE%\miniconda3
22+
set v_paths=%v_paths%;%ProgramData%\anaconda3
23+
set v_paths=%v_paths%;%USERPROFILE%\anaconda3
2524

26-
for %%a in (%paths%) do (
27-
IF NOT "%custom_conda_path%"=="" (
28-
set paths=%custom_conda_path%;%paths%
25+
for %%a in (%v_paths%) do (
26+
IF NOT "%v_custom_path%"=="" (
27+
set v_paths=%v_custom_path%;%v_paths%
2928
)
3029
)
3130

32-
for %%a in (%paths%) do (
31+
for %%a in (%v_paths%) do (
3332
if EXIST "%%a\Scripts\activate.bat" (
34-
SET CONDA_PATH=%%a
33+
SET v_conda_path=%%a
3534
echo anaconda3/miniconda3 detected in %%a
36-
goto :foundPath
35+
goto :CONDA_FOUND
3736
)
3837
)
3938

40-
IF "%CONDA_PATH%"=="" (
39+
IF "%v_conda_path%"=="" (
4140
echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html
4241
exit /b 1
4342
)
4443

44+
:CONDA_FOUND
45+
echo Stashing local changes and pulling latest update...
4546
call git stash
4647
call git pull
48+
call "%v_conda_path%\Scripts\activate.bat"
49+
50+
for /f "delims=" %%a in ('git log -1 --format^="%%H" -- environment.yaml') DO set v_cur_hash=%%a
51+
set /p "v_last_hash="<"z_version_env.tmp" 1>NUL 2>&1
52+
echo %v_cur_hash%>z_version_env.tmp
53+
54+
echo Current environment.yaml hash: %v_cur_hash%
55+
echo Previous environment.yaml hash: %v_last_hash%
56+
57+
if "%v_last_hash%" == "%v_cur_hash%" (
58+
echo environment.yaml version doesn't change
59+
) else (
60+
echo environment.yaml changed, updating dependencies
61+
call conda env create --name "%v_conda_env_name%" -f environment.yaml
62+
call conda env update --name "%v_conda_env_name%" -f environment.yaml
63+
)
4764

48-
:foundPath
49-
call "%CONDA_PATH%\Scripts\activate.bat"
50-
call conda env create -n "%conda_env_name%" -f environment.yaml
51-
call conda env update -n "%conda_env_name%" --file environment.yaml --prune
52-
call "%CONDA_PATH%\Scripts\activate.bat" "%conda_env_name%"
53-
python "%CD%"\scripts\relauncher.py
65+
call "%v_conda_path%\Scripts\activate.bat" "%v_conda_env_name%"
5466

5567
:PROMPT
5668
set SETUPTOOLS_USE_DISTUTILS=stdlib
5769
IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" (
58-
python scripts/relauncher.py
70+
set PYTHONPATH=%~dp0
71+
python scripts\relauncher.py
5972
) ELSE (
60-
ECHO Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
73+
echo Your model file does not exist! Place it in 'models\ldm\stable-diffusion-v1' with the name 'model.ckpt'.
74+
pause
6175
)

0 commit comments

Comments
 (0)