-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_windows.bat
More file actions
270 lines (237 loc) · 8.76 KB
/
setup_windows.bat
File metadata and controls
270 lines (237 loc) · 8.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
@echo off
setlocal EnableExtensions EnableDelayedExpansion
title MOSNA GUI — Installation Windows
rem =============================================================
rem MOSNA GUI — Windows installer
rem Double-click to run, or: setup_windows.bat [--no-shortcut]
rem Requirements: conda / miniconda (auto-installed if missing)
rem =============================================================
rem ── Configuration ────────────────────────────────────────────
set "ENV_NAME=mosna-GUI"
set "PYTHON_VERSION=3.10"
rem Resolve project root (folder containing this .bat)
set "PROJECT_DIR=%~dp0"
if "%PROJECT_DIR:~-1%"=="\" set "PROJECT_DIR=%PROJECT_DIR:~0,-1%"
set "GUI_SCRIPT=%PROJECT_DIR%\GUI_MOSNA.py"
set "MOSNA_PACKAGE=%PROJECT_DIR%\mosna-package"
set "ICON_FILE=%PROJECT_DIR%\assets\logo.ico"
set "LAUNCHER_BAT=%PROJECT_DIR%\MosnaGUI.bat"
set "DESKTOP_SHORTCUT=%USERPROFILE%\Desktop\MOSNA GUI.lnk"
set "MINICONDA_DIR=%USERPROFILE%\miniconda3"
set "MINICONDA_INSTALLER=%TEMP%\Miniconda3-latest-Windows-x86_64.exe"
set "MINICONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe"
set "CONDA_BAT="
set "CREATE_SHORTCUT=1"
rem ── Parse optional arguments ─────────────────────────────────
for %%A in (%*) do (
if /I "%%A"=="--no-shortcut" set "CREATE_SHORTCUT=0"
)
rem ── Banner ───────────────────────────────────────────────────
echo.
echo ============================================================
echo MOSNA GUI ^— Windows Installation
echo ============================================================
echo.
echo Project : %PROJECT_DIR%
echo.
rem ── Sanity checks ────────────────────────────────────────────
echo [0/5] Sanity checks...
if not exist "%GUI_SCRIPT%" (
echo [ERROR] GUI_MOSNA.py not found.
echo Run this script from the project root directory.
goto :fail
)
if not exist "%MOSNA_PACKAGE%" (
echo [ERROR] mosna-package directory not found:
echo %MOSNA_PACKAGE%
goto :fail
)
cd /d "%PROJECT_DIR%"
rem ── Locate conda ────────────────────────────────────────────
call :find_conda
if errorlevel 1 (
echo [INFO] Conda not found — downloading Miniconda automatically...
call :install_miniconda
if errorlevel 1 goto :fail
call :find_conda
if errorlevel 1 (
echo [ERROR] Conda still not found after Miniconda installation.
goto :fail
)
)
echo [OK] Conda: %CONDA_BAT%
echo.
rem ── Step 1: Environment ──────────────────────────────────────
echo [1/5] Conda environment "%ENV_NAME%"...
call :ensure_env
if errorlevel 1 goto :fail
rem ── Step 2: Conda packages ───────────────────────────────────
echo.
echo [2/5] Installing conda-forge packages...
call "%CONDA_BAT%" install -n "%ENV_NAME%" -y -c conda-forge ^
"python=%PYTHON_VERSION%" ^
pyside6 ^
pyyaml ^
pandas ^
pyarrow ^
"scipy=1.13" ^
scikit-learn ^
networkx ^
matplotlib ^
seaborn ^
scanpy ^
tqdm ^
lifelines ^
ipykernel ^
ipywidgets ^
markdown
if errorlevel 1 (
echo [ERROR] conda install failed.
goto :fail
)
echo [OK] Conda packages installed.
rem ── Step 3: mosna-package ────────────────────────────────────
echo.
echo [3/5] Installing mosna-package...
call "%CONDA_BAT%" run -n "%ENV_NAME%" python -m pip install "%MOSNA_PACKAGE%" --quiet
if errorlevel 1 (
echo [ERROR] mosna-package installation failed.
goto :fail
)
echo [OK] mosna-package installed.
rem ── Step 4: Verify imports ───────────────────────────────────
echo.
echo [4/5] Verifying key imports...
call "%CONDA_BAT%" run -n "%ENV_NAME%" python -c ^
"import PySide6, yaml, pandas, mosna; print('[OK] All imports successful.')"
if errorlevel 1 (
echo [ERROR] Import verification failed. Check the output above.
goto :fail
)
rem ── Step 5: Launcher + shortcut ──────────────────────────────
echo.
echo [5/5] Creating launcher and desktop shortcut...
rem Generate MosnaGUI.bat launcher
(
echo @echo off
echo rem Auto-generated by setup_windows.bat
echo set "CONDA_BAT=%CONDA_BAT%"
echo call "%%CONDA_BAT%%" activate "%ENV_NAME%"
echo cd /d "%PROJECT_DIR%"
echo python "%GUI_SCRIPT%"
) > "%LAUNCHER_BAT%"
echo [OK] Launcher: %LAUNCHER_BAT%
if "%CREATE_SHORTCUT%"=="1" (
call :create_shortcut
if errorlevel 1 (
echo [WARN] Could not create desktop shortcut ^(non-fatal^).
) else (
echo [OK] Shortcut: %DESKTOP_SHORTCUT%
)
) else (
echo [INFO] Desktop shortcut skipped ^(--no-shortcut^).
)
rem ── Done ─────────────────────────────────────────────────────
echo.
echo ============================================================
echo Installation complete!
echo ============================================================
echo.
echo To launch: double-click MosnaGUI.bat in the project folder
echo or the shortcut on your Desktop.
echo.
pause
goto :eof
rem =============================================================
rem Subroutines
rem =============================================================
:find_conda
set "CONDA_BAT="
if exist "%MINICONDA_DIR%\condabin\conda.bat" (
set "CONDA_BAT=%MINICONDA_DIR%\condabin\conda.bat"
exit /b 0
)
if exist "%USERPROFILE%\anaconda3\condabin\conda.bat" (
set "CONDA_BAT=%USERPROFILE%\anaconda3\condabin\conda.bat"
exit /b 0
)
if exist "%USERPROFILE%\Miniconda3\condabin\conda.bat" (
set "CONDA_BAT=%USERPROFILE%\Miniconda3\condabin\conda.bat"
exit /b 0
)
rem Search PATH
for /f "delims=" %%I in ('where conda.bat 2^>nul') do (
set "CONDA_BAT=%%I"
exit /b 0
)
exit /b 1
:install_miniconda
echo.
echo ── Miniconda auto-install ──────────────────────────────────
echo.
echo [INFO] Downloading installer from:
echo %MINICONDA_URL%
echo.
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"try { Invoke-WebRequest -Uri '%MINICONDA_URL%' -OutFile '%MINICONDA_INSTALLER%' -UseBasicParsing } catch { Write-Error $_; exit 1 }"
if errorlevel 1 (
echo [ERROR] Download failed. Check your internet connection.
exit /b 1
)
if not exist "%MINICONDA_INSTALLER%" (
echo [ERROR] Installer file missing after download.
exit /b 1
)
echo [INFO] Installing Miniconda silently to:
echo %MINICONDA_DIR%
start /wait "" "%MINICONDA_INSTALLER%" /InstallationType=JustMe /RegisterPython=0 /S /D=%MINICONDA_DIR%
if errorlevel 1 (
echo [ERROR] Miniconda installer returned an error.
exit /b 1
)
if not exist "%MINICONDA_DIR%\condabin\conda.bat" (
echo [ERROR] Miniconda installed but conda.bat not found.
exit /b 1
)
echo [OK] Miniconda installed at %MINICONDA_DIR%
exit /b 0
:ensure_env
call "%CONDA_BAT%" env list > "%TEMP%\mosna_envs.txt" 2>nul
if errorlevel 1 (
echo [ERROR] Cannot list conda environments.
exit /b 1
)
findstr /C:"%ENV_NAME%" "%TEMP%\mosna_envs.txt" >nul 2>nul
if not errorlevel 1 (
echo [OK] Environment "%ENV_NAME%" already exists — reusing.
del /f /q "%TEMP%\mosna_envs.txt" >nul 2>nul
exit /b 0
)
echo [INFO] Creating environment "%ENV_NAME%" ...
call "%CONDA_BAT%" create -n "%ENV_NAME%" python=%PYTHON_VERSION% -y
if errorlevel 1 (
echo [ERROR] conda env create failed.
del /f /q "%TEMP%\mosna_envs.txt" >nul 2>nul
exit /b 1
)
del /f /q "%TEMP%\mosna_envs.txt" >nul 2>nul
exit /b 0
:create_shortcut
set "ICON_ARG=%GUI_SCRIPT%"
if exist "%ICON_FILE%" set "ICON_ARG=%ICON_FILE%"
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$s = (New-Object -Com WScript.Shell).CreateShortcut('%DESKTOP_SHORTCUT%'); ^
$s.TargetPath = '%LAUNCHER_BAT%'; ^
$s.WorkingDirectory = '%PROJECT_DIR%'; ^
$s.IconLocation = '%ICON_ARG%'; ^
$s.Description = 'Launch MOSNA GUI'; ^
$s.Save()"
exit /b %ERRORLEVEL%
:fail
echo.
echo ============================================================
echo Installation FAILED — see errors above.
echo ============================================================
echo.
pause
exit /b 1