2026-06-28 19:11:13 +02:00

80 lines
2.0 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
REM Set file paths
set ROOT_DIR=%~dp0..
set CONFIG_FILE=%ROOT_DIR%\config.json
set REQUIREMENTS=%ROOT_DIR%\requirements.txt
set ENV_FILE=%ROOT_DIR%\.env
REM Check if .env file exists
if not exist "%ENV_FILE%" (
echo [ERROR] .env file not found. Please copy .env.example to .env and configure it.
exit /b 1
)
REM Extract config.json fields using PowerShell
for /f "delims=" %%i in ('powershell -NoProfile -Command ^
"Get-Content '%CONFIG_FILE%' | ConvertFrom-Json | Select-Object -ExpandProperty architecture"') do set ARCHITECTURE=%%i
REM Extract python path from .env file
for /f "usebackq tokens=2 delims==" %%i in (`findstr "PYTHON_PATH" "%ENV_FILE%"`) do set PYTHON_EXEC=%%i
REM Construct python executable path
set ENV_NAME=WINenv_%ARCHITECTURE%
set ENV_PATH=%ROOT_DIR%\%ENV_NAME%
if not exist "%PYTHON_EXEC%" (
echo [ERROR] Python introuvable à: %PYTHON_EXEC%
echo Veuillez vérifier votre .env ou le dossier d'installation.
exit /b 1
)
REM Show config info
echo [INFO] Configuration :
echo Python: %PYTHON_EXEC%
echo Env: %ENV_NAME%
REM Check if virtual environment exists
if not exist "%ENV_PATH%\Scripts" (
echo [INFO] Environnement virtuel introuvable, création...
"%PYTHON_EXEC%" -m venv "%ENV_PATH%"
echo [INFO] Installation des dépendances...
"%ENV_PATH%\Scripts\python" -m pip install --upgrade pip
"%ENV_PATH%\Scripts\python" -m pip install -r "%REQUIREMENTS%"
) else (
echo [INFO] Environnement virtuel trouvé.
)
REM Activate and launch VS Code
echo [INFO] Lancement de VS Code...
call "%ENV_PATH%/Scripts/activate.bat"
set "CODE_EXE="
for /f "delims=" %%i in ('where code 2^>nul') do (
set "CODE_CMD=%%~fi"
goto :found
)
echo [ERROR] VS Code CLI not found.
exit /b 1
:found
for %%i in ("%CODE_CMD%") do (
set "CODE_BIN=%%~dpi"
)
for %%i in ("%CODE_BIN%..") do (
set "VSCODE_ROOT=%%~fi"
)
set "CODE_EXE=%VSCODE_ROOT%\Code.exe"
if exist "%CODE_EXE%" (
start "" "%CODE_EXE%" "%ROOT_DIR%"
) else (
start "" code "%ROOT_DIR%"
)
exit