Quand l'embed est livre complet (socketio + tkinter pre-embarques), le bootstrap get-pip.py + pip install echouait hors-ligne. Ajout d'un guard : si 'import socketio, tkinter' OK -> on saute pip (offline). Mode online legacy conserve si embed nu. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
122 lines
4.0 KiB
PowerShell
122 lines
4.0 KiB
PowerShell
# ============================================================
|
|
# configure_embed.ps1 — Configure le runtime Python embedded
|
|
# ------------------------------------------------------------
|
|
#
|
|
# Quand le composant 'pythonembed' est installe, on a :
|
|
# <AppDir>\python-embed\ <-- runtime Python 3.12 embedded
|
|
#
|
|
# Ce script :
|
|
# 1. Active l'import des packages (patch de python312._pth)
|
|
# 2. Installe pip dans le runtime embedded
|
|
# 3. Installe les dependances requirements_agent.txt
|
|
# 4. Reecrit Lea.bat pour pointer sur python-embed\pythonw.exe
|
|
#
|
|
# Doit etre execute avec le CWD = <AppDir>
|
|
# ============================================================
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$AppDir = Get-Location
|
|
$EmbedDir = Join-Path $AppDir "python-embed"
|
|
$PythonExe = Join-Path $EmbedDir "python.exe"
|
|
|
|
if (-not (Test-Path $PythonExe)) {
|
|
Write-Host "Python embedded introuvable, abandon."
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Configuration de Python embedded..."
|
|
|
|
# ---------------------------------------------------------------
|
|
# 1. Decommenter la ligne 'import site' dans python312._pth
|
|
# (necessaire pour que pip puisse fonctionner)
|
|
# ---------------------------------------------------------------
|
|
$PthFile = Get-ChildItem -Path $EmbedDir -Filter "python*._pth" | Select-Object -First 1
|
|
if ($PthFile) {
|
|
$Content = Get-Content $PthFile.FullName
|
|
$NewContent = $Content -replace '^#import site', 'import site'
|
|
Set-Content -Path $PthFile.FullName -Value $NewContent
|
|
Write-Host " python._pth patche (import site active)"
|
|
}
|
|
|
|
# ---------------------------------------------------------------
|
|
# 2-3. Dependances Python
|
|
# Si l'embed est livre complet (deps + tkinter pre-embarques),
|
|
# on saute le bootstrap pip / install : INSTALL HORS-LIGNE possible.
|
|
# Sinon (embed nu), on bootstrap pip + installe requirements (mode online).
|
|
# ---------------------------------------------------------------
|
|
$DepsOk = $false
|
|
& $PythonExe -c "import socketio, tkinter" 2>$null
|
|
if ($LASTEXITCODE -eq 0) { $DepsOk = $true }
|
|
|
|
if ($DepsOk) {
|
|
Write-Host " Dependances deja embarquees (socketio + tkinter) - pip saute (offline OK)."
|
|
} else {
|
|
# Bootstrap pip (necessite internet)
|
|
$GetPip = Join-Path $env:TEMP "get-pip.py"
|
|
Write-Host " Telechargement de get-pip.py..."
|
|
Invoke-WebRequest -Uri "https://bootstrap.pypa.io/get-pip.py" -OutFile $GetPip -UseBasicParsing
|
|
|
|
Write-Host " Installation de pip..."
|
|
& $PythonExe $GetPip --no-warn-script-location
|
|
Remove-Item $GetPip -Force
|
|
|
|
$Requirements = Join-Path $AppDir "requirements_agent.txt"
|
|
if (Test-Path $Requirements) {
|
|
Write-Host " Installation des dependances Python..."
|
|
& $PythonExe -m pip install --no-warn-script-location -r $Requirements
|
|
}
|
|
}
|
|
|
|
# ---------------------------------------------------------------
|
|
# 4. Reecrire Lea.bat pour utiliser python-embed
|
|
# ---------------------------------------------------------------
|
|
$LeaBat = Join-Path $AppDir "Lea.bat"
|
|
$NewLeaBat = @"
|
|
@echo off
|
|
chcp 65001 >nul 2>&1
|
|
title Lea - Assistante IA
|
|
cd /d "%~dp0"
|
|
|
|
if exist "lea_agent.lock" (
|
|
for /f "usebackq tokens=* delims=" %%i in ("lea_agent.lock") do (
|
|
taskkill /F /PID %%i >nul 2>&1
|
|
)
|
|
del /f /q "lea_agent.lock" >nul 2>&1
|
|
timeout /t 2 >nul
|
|
)
|
|
|
|
if exist "config.txt" (
|
|
for /f "usebackq eol=# tokens=1,* delims==" %%a in ("config.txt") do (
|
|
if not "%%a"=="" if not "%%b"=="" set "%%a=%%b"
|
|
)
|
|
)
|
|
|
|
echo.
|
|
echo Demarrage de Lea (runtime embedded)...
|
|
echo.
|
|
|
|
start "" /b "%~dp0python-embed\pythonw.exe" run_agent_v1.py
|
|
|
|
timeout /t 3 >nul
|
|
set "LEA_ALIVE=0"
|
|
if exist "lea_agent.lock" (
|
|
for /f "usebackq tokens=* delims=" %%i in ("lea_agent.lock") do (
|
|
tasklist /FI "PID eq %%i" /NH 2>nul | findstr /I "pythonw" >nul && set "LEA_ALIVE=1"
|
|
)
|
|
)
|
|
if "%LEA_ALIVE%"=="0" (
|
|
echo.
|
|
echo Lea n'a pas demarre correctement. Affichage des erreurs :
|
|
echo.
|
|
"%~dp0python-embed\python.exe" run_agent_v1.py
|
|
pause
|
|
)
|
|
"@
|
|
|
|
Set-Content -Path $LeaBat -Value $NewLeaBat -Encoding ASCII
|
|
Write-Host " Lea.bat reecrit pour runtime embedded"
|
|
|
|
Write-Host "Configuration terminee."
|
|
exit 0
|