added run scripts for windows.

This commit is contained in:
2026-01-02 11:40:15 +01:00
parent 32b541642b
commit 86377f7193
2 changed files with 148 additions and 0 deletions

69
run.bat Normal file
View File

@@ -0,0 +1,69 @@
:: @echo off
SETLOCAL EnableExtensions
SET "BASE_DIR=%~dp0"
cd /d "%BASE_DIR%"
:: --- CONFIGURATION ---
SET "APPNAME=testium"
SET "VENV_DIR=%BASE_DIR%test\tmp\%APPNAME%_venv"
SET "PYTHON_EXE=python"
SET "SCRIPT_NAME=src\%APPNAME%"
SET "REQUIREMENTS=src\requirements.txt"
echo [1/4] Verification of Python...
py --version >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
SET "PYTHON_EXE=py"
goto :PYTHON_FOUND
)
python --version >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
SET "PYTHON_EXE=python"
goto :PYTHON_FOUND
)
:: If we reach here, python could not be found
echo.
echo ###########################################################
echo ERROR : Python could not be found on this system.
echo ###########################################################
pause
exit /b
:PYTHON_FOUND
:: --- VENV creation ---
if not exist "%VENV_DIR%" (
echo [2/4] Virtual environment creation...
%PYTHON_EXE% -m venv %VENV_DIR%
if %ERRORLEVEL% neq 0 (
echo ERROR while creating the venv.
pause
exit /b
)
) else (
echo [2/4] Virtual environment already here.
)
:: --- ACTIVATION AND DEPENDANCES ---
echo [3/4] Activation of the venv and installation of dependencies...
call "%VENV_DIR%\Scripts\activate"
if exist "%BASE_DIR%%REQUIREMENTS%" (
pip install --upgrade pip
pip install -r "%BASE_DIR%%REQUIREMENTS%"
) else (
echo Info : No '%REQUIREMENTS%' file found, dependencies ignored.
)
:: --- Application launching ---
echo [4/4] Launch of %APPNAME%...
python "%BASE_DIR%%SCRIPT_NAME%"
:: --- FIN ---
echo.
echo %APPNAME% finished
deactivate

79
run.ps1 Normal file
View File

@@ -0,0 +1,79 @@
$AppName = "testium"
# 1. Set working directory to the script's location
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
Set-Location -Path $PSScriptRoot
$VenvPath = Join-Path $PSScriptRoot $(Join-Path "test\tmp\" ("$AppName"+"_venv"))
$Requirements = Join-Path $PSScriptRoot "src\requirements.txt"
$PythonScript = Join-Path $PSScriptRoot $(Join-Path "src" "$AppName")
Write-Host "[1/4] Searching for Python..." -ForegroundColor Cyan
# 2. Python detection (checks for 'python' then 'py' launcher)
$PythonExe = Get-Command python.exe -ErrorAction SilentlyContinue
if (-not $PythonExe) {
$PythonExe = Get-Command py.exe -ErrorAction SilentlyContinue
}
if (-not $PythonExe) {
Write-Host "###########################################################" -ForegroundColor Red
Write-Host "ERROR: Python was not detected on this system."
Write-Host "Please install Python and check 'Add Python to PATH'."
Write-Host "###########################################################" -ForegroundColor Red
Pause
exit
}
Write-Host "[+] Python found: $($PythonExe.Source)" -ForegroundColor Green
# 3. Virtual Environment management
if (-not (Test-Path $VenvPath)) {
Write-Host "[2/4] Creating virtual environment..." -ForegroundColor Cyan
& $PythonExe.Source -m venv $VenvPath
} else {
Write-Host "[2/4] Virtual environment already exists." -ForegroundColor Green
}
# 4. Activation and Dependencies
Write-Host "[3/4] Activating venv and updating dependencies..." -ForegroundColor Cyan
$ActivateScript = Join-Path $VenvPath "Scripts\Activate.ps1"
# Execute the activation script
& $ActivateScript
if ($env:VIRTUAL_ENV -and (Test-Path $env:VIRTUAL_ENV)) {
Write-Host "[+] Verified: Running inside venv ($env:VIRTUAL_ENV)" -ForegroundColor Green
} else {
Write-Host "ERROR: Failed to activate virtual environment. Aborting install." -ForegroundColor Red
pause
exit
}
# 5. Execution
try {
if (Test-Path $Requirements) {
Write-Host "[+] Installing requirements..." -ForegroundColor Yellow
python -m pip install --upgrade pip --quiet
pip install -r $Requirements
}
if (-not (Test-Path $PythonScript)) {
Write-Host "ERROR: File '$PythonScript' not found in $PSScriptRoot" -ForegroundColor Red
}
Write-Host "[4/4] Starting $AppName..." -ForegroundColor Cyan
Write-Host "-----------------------------------------------------------" -ForegroundColor Gray
python $PythonScript
}
catch {
Write-Host "An error occurred during execution." -ForegroundColor Red
}
finally {
# This runs even if the script fails
if (Get-Command deactivate -ErrorAction SilentlyContinue) {
deactivate
Write-Host "Virtual environment deactivated." -ForegroundColor Gray
}
}
Write-Host "-----------------------------------------------------------" -ForegroundColor Gray
Write-Host "$AppName execution finished."