-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.bat
More file actions
185 lines (159 loc) · 5.1 KB
/
Copy pathsetup.bat
File metadata and controls
185 lines (159 loc) · 5.1 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
@echo off
setlocal DisableDelayedExpansion
for %%I in ("%~dp0.") do set "PROJECT_ROOT=%%~fI"
set "APP_DIR=%PROJECT_ROOT%\MeadowPy"
if not exist "%APP_DIR%\meadowpy\__init__.py" (
echo.
echo [ERROR] The MeadowPy application folder was not found.
echo Keep setup.bat next to the MeadowPy folder and try again.
echo.
pause
exit /b 1
)
cd /d "%APP_DIR%"
set "INSTALL_DEV=0"
if /I "%~1"=="--dev" (
set "INSTALL_DEV=1"
)
echo.
echo =============================================
echo MeadowPy Setup
echo =============================================
echo.
:: -----------------------------------------------------------
:: 1. Find Python 3.11+
:: -----------------------------------------------------------
set "PYTHON_CMD="
:: Try py launcher first (most reliable on Windows)
py -3 --version >nul 2>&1
if not errorlevel 1 (
set "PYTHON_CMD=py -3"
goto :check_version
)
:: Try python
python --version >nul 2>&1
if not errorlevel 1 (
set "PYTHON_CMD=python"
goto :check_version
)
:: Try python3
python3 --version >nul 2>&1
if not errorlevel 1 (
set "PYTHON_CMD=python3"
goto :check_version
)
echo [ERROR] Python was not found on this computer.
echo.
echo Please install Python 3.11 or newer from:
echo https://www.python.org/downloads/
echo.
echo IMPORTANT: Check the box that says
echo "Add Python to PATH" during installation.
echo.
pause
exit /b 1
:: -----------------------------------------------------------
:: 2. Verify version is 3.11+
:: -----------------------------------------------------------
:check_version
for /f "tokens=2 delims= " %%v in ('%PYTHON_CMD% --version 2^>^&1') do set "PY_VER=%%v"
for /f "tokens=1,2 delims=." %%a in ("%PY_VER%") do (
set "PY_MAJOR=%%a"
set "PY_MINOR=%%b"
)
if %PY_MAJOR% lss 3 goto :bad_version
if %PY_MAJOR% equ 3 if %PY_MINOR% lss 11 goto :bad_version
echo Found Python %PY_VER%
echo.
goto :setup_venv
:bad_version
echo [ERROR] Python %PY_VER% was found, but MeadowPy requires 3.11 or newer.
echo.
echo Please download a newer version from:
echo https://www.python.org/downloads/
echo.
pause
exit /b 1
:: -----------------------------------------------------------
:: 3. Create or repair the virtual environment
:: -----------------------------------------------------------
:setup_venv
set "VENV_OK=0"
if exist ".venv\Scripts\python.exe" (
.venv\Scripts\python.exe -c "import sys" >nul 2>&1
if errorlevel 1 (
echo Found a broken virtual environment - recreating...
rmdir /s /q ".venv"
) else (
set "VENV_OK=1"
echo Virtual environment already exists - skipping creation.
)
)
if "%VENV_OK%"=="0" (
if exist ".venv" (
echo Found a broken virtual environment - recreating...
rmdir /s /q ".venv"
)
echo Creating virtual environment...
%PYTHON_CMD% -m venv .venv
if errorlevel 1 (
echo.
echo [ERROR] Failed to create virtual environment.
echo Please make sure Python is installed correctly.
pause
exit /b 1
)
)
:: -----------------------------------------------------------
:: 4. Install dependencies
:: -----------------------------------------------------------
echo Upgrading pip...
.venv\Scripts\python.exe -m pip install --upgrade pip -q
if "%INSTALL_DEV%"=="1" (
echo Installing app + test dependencies...
.venv\Scripts\python.exe -m pip install -r dev\requirements-dev.txt -q
) else (
echo Installing dependencies...
.venv\Scripts\python.exe -m pip install -r meadowpy\requirements.txt -q
)
if errorlevel 1 (
echo.
echo [ERROR] Failed to install dependencies.
echo Check your internet connection and try again.
pause
exit /b 1
)
:: -----------------------------------------------------------
:: 5. Quick verification
:: -----------------------------------------------------------
.venv\Scripts\python.exe -c "from PyQt6.QtWidgets import QApplication" >nul 2>&1
if errorlevel 1 (
echo.
echo [WARNING] PyQt6 installed but could not be verified.
echo MeadowPy may still work - try launching it.
echo.
)
:: -----------------------------------------------------------
:: 6. Create desktop-style shortcut with icon
:: -----------------------------------------------------------
echo Creating MeadowPy shortcut...
powershell -NoProfile -ExecutionPolicy Bypass -File "%APP_DIR%\meadowpy\resources\create_shortcut.ps1" -ShortcutPath "%PROJECT_ROOT%\MeadowPy.lnk" -AppDirectory "%APP_DIR%"
if errorlevel 1 goto :shortcut_failed
if not exist "%PROJECT_ROOT%\MeadowPy.lnk" goto :shortcut_failed
echo Shortcut created successfully.
goto :shortcut_done
:shortcut_failed
echo [WARNING] Could not create shortcut. You can still use "MeadowPy\Run MeadowPy.bat".
:shortcut_done
:: -----------------------------------------------------------
:: Done
:: -----------------------------------------------------------
echo.
echo =============================================
echo Setup complete!
echo.
echo Double-click "MeadowPy" to start.
if "%INSTALL_DEV%"=="1" echo Use "MeadowPy\dev\Run Tests.bat" to run the test suite.
echo =============================================
echo.
pause