Optimize dependency installation in start scripts to skip if already satisfied

This commit is contained in:
Abolfazl
2026-05-09 19:28:28 +03:30
parent f0b2d46c49
commit ff3150e500
2 changed files with 38 additions and 18 deletions
+12
View File
@@ -39,6 +39,17 @@ if not exist "%VENV_DIR%\Scripts\python.exe" (
set "VPY=%VENV_DIR%\Scripts\python.exe"
REM -------- Skip dependency install when all required packages are already importable.
REM Pip install (even with -q) takes ~3-8s every launch; this drops it to ~0.1s
REM on warm runs. Falls through to the install path on first run, after a
REM requirements.txt change, or when any import fails for any reason.
set "DEPS_OK=0"
"%VPY%" -c "import cryptography, h2, brotli, zstandard" >nul 2>&1
if !errorlevel!==0 set "DEPS_OK=1"
if "!DEPS_OK!"=="1" (
echo [*] Dependencies already installed — skipping pip install.
) else (
echo [*] Installing dependencies ...
"%VPY%" -m pip install --disable-pip-version-check -q --upgrade pip >nul
"%VPY%" -m pip install --disable-pip-version-check -q -r requirements.txt
@@ -53,6 +64,7 @@ if errorlevel 1 (
exit /b 1
)
)
)
if not exist "config.json" (
echo [*] No config.json found — launching setup wizard ...
+8
View File
@@ -34,6 +34,13 @@ fi
VPY="$VENV_DIR/bin/python"
# Skip dependency install when all required packages are already importable.
# Pip install (even with -q) takes ~3-8s every launch; this drops it to <0.1s
# on warm runs. Falls through to the install path on first run or if any
# import fails for any reason.
if "$VPY" -c "import cryptography, h2, brotli, zstandard" >/dev/null 2>&1; then
echo "[*] Dependencies already installed — skipping pip install."
else
echo "[*] Installing dependencies ..."
"$VPY" -m pip install --disable-pip-version-check -q --upgrade pip >/dev/null
if ! "$VPY" -m pip install --disable-pip-version-check -q -r requirements.txt; then
@@ -42,6 +49,7 @@ if ! "$VPY" -m pip install --disable-pip-version-check -q -r requirements.txt; t
-i https://mirror-pypi.runflare.com/simple/ \
--trusted-host mirror-pypi.runflare.com
fi
fi
if [ ! -f "config.json" ]; then
echo "[*] No config.json found — launching setup wizard ..."