Always run in a project virtual environment

This commit is contained in:
Sterling Archer committed 2026-08-12 10:06:30 -07:00
1 parent 2a9e9cda4c
commit 89f841b31f
4 files changed
+166 -79

No files matched your search

+83 -12
View File
@@ -1,35 +1,106 @@
@echo off
setlocal
setlocal enabledelayedexpansion
cd /d "%~dp0"
if "%SOLIXAUTO_HOME%"=="" (
set "DATA_DIR=%USERPROFILE%\solix-automation"
) else (
set "DATA_DIR=%SOLIXAUTO_HOME%"
)
set "VENV_DIR=%DATA_DIR%\venv"
set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
echo.
echo ==============================================================
echo Anker SOLIX to Shelly automation - setup
echo Anker SOLIX to Shelly automation
echo ==============================================================
echo.
set PYTHON=
for %%P in (py python) do (
if not defined PYTHON (
where %%P >nul 2>&1 && set PYTHON=%%P
if exist "%VENV_PYTHON%" (
"%VENV_PYTHON%" -c "import anker_solix_api.api, yaml, aiohttp" >nul 2>&1
if not errorlevel 1 (
echo Using: %VENV_PYTHON%
echo.
"%VENV_PYTHON%" "%~dp0solixauto.py" setup
goto :end
)
)
if not defined PYTHON (
echo No Python found on PATH.
echo Install Python 3.12 or newer from https://www.python.org/downloads/
set "BASE="
for %%P in (py python) do (
if not defined BASE (
where %%P >nul 2>&1 && set "BASE=%%P"
)
)
if not defined BASE (
echo Python 3.12 or newer is required and was not found on PATH.
echo Install it from https://www.python.org/downloads/
echo Tick "Add python.exe to PATH" during installation, then run this again.
echo.
pause
exit /b 1
)
echo Using: %PYTHON%
where git >nul 2>&1
if errorlevel 1 (
echo Git is required to fetch the Anker library, and was not found.
echo Install it from https://git-scm.com/download/win
echo.
pause
exit /b 1
)
echo This project runs in its own Python environment, so that installing or
echo removing packages elsewhere on this machine cannot break your automation.
echo.
echo It will be created at:
echo %VENV_DIR%
echo.
set /p REPLY="Set it up now? [Y/n]: "
if /i "%REPLY%"=="n" (
echo Nothing was changed.
goto :end
)
%PYTHON% "%~dp0solixauto.py" setup
echo.
echo Creating the environment...
if not exist "%DATA_DIR%" mkdir "%DATA_DIR%"
if exist "%VENV_DIR%" rmdir /s /q "%VENV_DIR%"
%BASE% -m venv "%VENV_DIR%"
if not exist "%VENV_PYTHON%" (
echo Could not create a virtual environment at %VENV_DIR%
pause
exit /b 1
)
echo Installing packages. This takes a minute.
echo.
"%VENV_PYTHON%" -m pip install --upgrade pip --quiet
"%VENV_PYTHON%" -m pip install -r "%~dp0requirements.txt" --quiet
"%VENV_PYTHON%" -m pip install "git+https://github.com/thomluther/anker-solix-api.git" --quiet
"%VENV_PYTHON%" -m pip install aiofiles cryptography paho-mqtt --quiet
"%VENV_PYTHON%" -c "import anker_solix_api.api" >nul 2>&1
if errorlevel 1 (
echo.
echo The install finished but the Anker library still will not import.
echo Run this to see the error:
echo "%VENV_PYTHON%" -c "import anker_solix_api.api"
pause
exit /b 1
)
echo.
echo Environment ready.
echo.
echo From now on, run commands with:
echo "%VENV_PYTHON%" solixauto.py ^<command^>
echo.
"%VENV_PYTHON%" "%~dp0solixauto.py" setup
:end
echo.
pause