-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
94 lines (83 loc) · 2.43 KB
/
setup.bat
File metadata and controls
94 lines (83 loc) · 2.43 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
@echo off
setlocal
:: === Configuration ===
set "VENV_DIR=.venv"
set "REQ_FILE=requirements.txt"
set "ENV_ACTIVE=0"
:: --- Change working directory to the folder where the script is located ---
cd /d "%~dp0" || (
echo [ERROR] Failed to set working directory to script location: %~dp0
call :Cleanup
exit /b 1
)
:: --------------------------------------------
:: Check if not running in own env
:: --------------------------------------------
if /i "%VIRTUAL_ENV%"=="%CD%\%VENV_DIR%" (
echo [ERROR] This script is already running inside the target virtual environment.
exit /b 1
)
:: --------------------------------------------
:: Check for Python installation
:: --------------------------------------------
python --version >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Python is not installed or not in PATH.
call :Cleanup
exit /b 1
)
echo [OK] Python is available.
:: --------------------------------------------
:: Create virtual environment
:: --------------------------------------------
echo Creating virtual environment in "%VENV_DIR%"...
python -m venv "%VENV_DIR%"
if %errorlevel% neq 0 (
echo [ERROR] Failed to create virtual environment.
call :Cleanup
exit /b 1
)
:: --------------------------------------------
:: Activate virtual environment
:: --------------------------------------------
call "%VENV_DIR%\Scripts\activate.bat"
if /i not "%VIRTUAL_ENV%"=="%CD%\%VENV_DIR%" (
echo [ERROR] Failed to activate virtual environment.
call :Cleanup
exit /b 1
)
set "ENV_ACTIVE=1"
echo [OK] Virtual environment activated.
:: --------------------------------------------
:: Install requirements
:: --------------------------------------------
if not exist "%REQ_FILE%" (
echo [ERROR] Requirements file not found: %REQ_FILE%
call :Cleanup
exit /b 1
)
echo Installing packages from "%REQ_FILE%"...
pip install -r "%REQ_FILE%"
if %errorlevel% neq 0 (
echo [ERROR] Failed to install packages.
call :Cleanup
exit /b 1
)
echo [OK] All packages installed successfully.
:: --------------------------------------------
:: Normal cleanup
:: --------------------------------------------
call :Cleanup
echo [SUCCESS] Setup complete.
endlocal
exit /b 0
:: --------------------------------------------
:: Cleanup function
:: --------------------------------------------
:Cleanup
if "%ENV_ACTIVE%"=="1" (
deactivate
set "ENV_ACTIVE=0"
echo [OK] Virtual environment deactivated.
)
exit /b 0