diff --git a/run_device_main.bat b/run_device_main.bat index 8d5e9ac..c37b447 100644 --- a/run_device_main.bat +++ b/run_device_main.bat @@ -4,40 +4,45 @@ setlocal set "PROJECT_DIR=%~dp0" pushd "%PROJECT_DIR%" >nul || ( echo Failed to switch to project directory: %PROJECT_DIR% + pause exit /b 1 ) set "VENV_DIR=.venv" 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 if errorlevel 1 goto :error "%PYTHON_EXE%" %PYTHON_ARGS% -m venv "%VENV_DIR%" if errorlevel 1 goto :error -:venv_ready - -call "%VENV_ACTIVATE%" -if errorlevel 1 goto :error - if exist "requirements.txt" ( echo Installing dependencies... - python -m pip install --disable-pip-version-check -r requirements.txt - if errorlevel 1 goto :error + "%VENV_PYTHON%" -m pip install --disable-pip-version-check -r requirements.txt + 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 ( echo requirements.txt not found. Skipping dependency installation. ) +:run echo Starting laser_control.gui.main... -python -m laser_control.gui.main +"%VENV_PYTHON%" -m laser_control.gui.main set "EXIT_CODE=%ERRORLEVEL%" popd >nul +if not "%EXIT_CODE%"=="0" pause exit /b %EXIT_CODE% :find_python @@ -62,4 +67,5 @@ exit /b 1 set "EXIT_CODE=%ERRORLEVEL%" echo Script failed with exit code %EXIT_CODE%. popd >nul +pause exit /b %EXIT_CODE%