|
3 | 3 | :: Run all commands using this script's directory as the working directory
|
4 | 4 | cd %~dp0
|
5 | 5 |
|
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 |
11 | 12 |
|
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 |
14 | 14 |
|
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 |
17 | 18 | )
|
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 |
20 | 19 |
|
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 |
25 | 24 |
|
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% |
29 | 28 | )
|
30 | 29 | )
|
31 | 30 |
|
32 |
| -for %%a in (%paths%) do ( |
| 31 | +for %%a in (%v_paths%) do ( |
33 | 32 | if EXIST "%%a\Scripts\activate.bat" (
|
34 |
| - SET CONDA_PATH=%%a |
| 33 | + SET v_conda_path=%%a |
35 | 34 | echo anaconda3/miniconda3 detected in %%a
|
36 |
| - goto :foundPath |
| 35 | + goto :CONDA_FOUND |
37 | 36 | )
|
38 | 37 | )
|
39 | 38 |
|
40 |
| -IF "%CONDA_PATH%"=="" ( |
| 39 | +IF "%v_conda_path%"=="" ( |
41 | 40 | echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html
|
42 | 41 | exit /b 1
|
43 | 42 | )
|
44 | 43 |
|
| 44 | +:CONDA_FOUND |
| 45 | +echo Stashing local changes and pulling latest update... |
45 | 46 | call git stash
|
46 | 47 | 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 | +) |
47 | 64 |
|
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%" |
54 | 66 |
|
55 | 67 | :PROMPT
|
56 | 68 | set SETUPTOOLS_USE_DISTUTILS=stdlib
|
57 | 69 | IF EXIST "models\ldm\stable-diffusion-v1\model.ckpt" (
|
58 |
| - python scripts/relauncher.py |
| 70 | + set PYTHONPATH=%~dp0 |
| 71 | + python scripts\relauncher.py |
59 | 72 | ) 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 |
61 | 75 | )
|
0 commit comments