some improvements
This commit is contained in:
@ -4,40 +4,45 @@ setlocal
|
|||||||
set "PROJECT_DIR=%~dp0"
|
set "PROJECT_DIR=%~dp0"
|
||||||
pushd "%PROJECT_DIR%" >nul || (
|
pushd "%PROJECT_DIR%" >nul || (
|
||||||
echo Failed to switch to project directory: %PROJECT_DIR%
|
echo Failed to switch to project directory: %PROJECT_DIR%
|
||||||
|
pause
|
||||||
exit /b 1
|
exit /b 1
|
||||||
)
|
)
|
||||||
|
|
||||||
set "VENV_DIR=.venv"
|
set "VENV_DIR=.venv"
|
||||||
set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
|
set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
|
||||||
set "VENV_ACTIVATE=%VENV_DIR%\Scripts\activate.bat"
|
|
||||||
|
|
||||||
if exist "%VENV_PYTHON%" goto venv_ready
|
rem --- If the venv already exists, just run the app (works fully offline) ---
|
||||||
|
if exist "%VENV_PYTHON%" goto run
|
||||||
|
|
||||||
echo Creating virtual environment...
|
rem --- First run only: create venv and install dependencies (needs internet) ---
|
||||||
|
echo Virtual environment not found. Creating it (internet required, one time only)...
|
||||||
call :find_python
|
call :find_python
|
||||||
if errorlevel 1 goto :error
|
if errorlevel 1 goto :error
|
||||||
|
|
||||||
"%PYTHON_EXE%" %PYTHON_ARGS% -m venv "%VENV_DIR%"
|
"%PYTHON_EXE%" %PYTHON_ARGS% -m venv "%VENV_DIR%"
|
||||||
if errorlevel 1 goto :error
|
if errorlevel 1 goto :error
|
||||||
|
|
||||||
:venv_ready
|
|
||||||
|
|
||||||
call "%VENV_ACTIVATE%"
|
|
||||||
if errorlevel 1 goto :error
|
|
||||||
|
|
||||||
if exist "requirements.txt" (
|
if exist "requirements.txt" (
|
||||||
echo Installing dependencies...
|
echo Installing dependencies...
|
||||||
python -m pip install --disable-pip-version-check -r requirements.txt
|
"%VENV_PYTHON%" -m pip install --disable-pip-version-check -r requirements.txt
|
||||||
if errorlevel 1 goto :error
|
if errorlevel 1 (
|
||||||
|
echo.
|
||||||
|
echo Failed to install dependencies. Check your internet connection and run again.
|
||||||
|
rem Remove the half-baked venv so the next run retries cleanly.
|
||||||
|
rmdir /s /q "%VENV_DIR%"
|
||||||
|
goto :error
|
||||||
|
)
|
||||||
) else (
|
) else (
|
||||||
echo requirements.txt not found. Skipping dependency installation.
|
echo requirements.txt not found. Skipping dependency installation.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
:run
|
||||||
echo Starting laser_control.gui.main...
|
echo Starting laser_control.gui.main...
|
||||||
python -m laser_control.gui.main
|
"%VENV_PYTHON%" -m laser_control.gui.main
|
||||||
set "EXIT_CODE=%ERRORLEVEL%"
|
set "EXIT_CODE=%ERRORLEVEL%"
|
||||||
|
|
||||||
popd >nul
|
popd >nul
|
||||||
|
if not "%EXIT_CODE%"=="0" pause
|
||||||
exit /b %EXIT_CODE%
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:find_python
|
:find_python
|
||||||
@ -62,4 +67,5 @@ exit /b 1
|
|||||||
set "EXIT_CODE=%ERRORLEVEL%"
|
set "EXIT_CODE=%ERRORLEVEL%"
|
||||||
echo Script failed with exit code %EXIT_CODE%.
|
echo Script failed with exit code %EXIT_CODE%.
|
||||||
popd >nul
|
popd >nul
|
||||||
|
pause
|
||||||
exit /b %EXIT_CODE%
|
exit /b %EXIT_CODE%
|
||||||
|
|||||||
Reference in New Issue
Block a user