From db3b59af0fd64bbd4929c3dbdbd08168e241c692 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Sun, 22 Mar 2026 11:57:24 +0100 Subject: [PATCH] [InstallScripts] add dependencies install scripts --- install_scripts/install_all_dependencies.bat | 84 ++++++++++++++++++++ install_scripts/install_all_dependencies.sh | 78 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 install_scripts/install_all_dependencies.bat create mode 100644 install_scripts/install_all_dependencies.sh diff --git a/install_scripts/install_all_dependencies.bat b/install_scripts/install_all_dependencies.bat new file mode 100644 index 0000000000..afa13adc55 --- /dev/null +++ b/install_scripts/install_all_dependencies.bat @@ -0,0 +1,84 @@ +@echo off +setlocal EnableDelayedExpansion + +REM Install Python dependencies from requirements files at the OctoBot repo root +REM and under OctoBot\packages (any subdirectory). +REM PKG_IGNORE_DIRS: space-separated basenames under packages\ to skip (blacklist). Default: binary +REM dev_requirements.txt under packages\ is ignored; repo root dev_requirements.txt is used. +REM One pip install with multiple -r flags. + +cd /d "%~dp0.." +set "OCTOBOT_ROOT=%CD%" +set "PKG_IGNORE_DIRS=binary" + +set "PY=" +where python3 >nul 2>&1 && set "PY=python3" +if not defined PY where python >nul 2>&1 && set "PY=python" +if not defined PY ( + echo error: neither python3 nor python found in PATH 1>&2 + exit /b 1 +) + +set "REQ_ALL=%TEMP%\octobot_all_req_%RANDOM%_%RANDOM%.txt" +(type nul)>"%REQ_ALL%" + +if exist "%OCTOBOT_ROOT%\full_requirements.txt" >>"%REQ_ALL%" echo %OCTOBOT_ROOT%\full_requirements.txt +if exist "%OCTOBOT_ROOT%\requirements.txt" >>"%REQ_ALL%" echo %OCTOBOT_ROOT%\requirements.txt +if exist "%OCTOBOT_ROOT%\dev_requirements.txt" >>"%REQ_ALL%" echo %OCTOBOT_ROOT%\dev_requirements.txt + +set "PACKAGES_DIR=%OCTOBOT_ROOT%\packages" +if exist "%PACKAGES_DIR%" ( + set "REQ_PKG=%TEMP%\octobot_pkg_!RANDOM!_!RANDOM!.txt" + (type nul)>"!REQ_PKG!" + set "LIST_OUT=!REQ_PKG!" + for /r "%PACKAGES_DIR%" %%F in (full_requirements.txt) do call :append_if_not_blacklisted "%%F" + for /r "%PACKAGES_DIR%" %%F in (requirements.txt) do call :append_if_not_blacklisted "%%F" + sort "!REQ_PKG!" /o "!REQ_PKG!.sorted" + type "!REQ_PKG!.sorted" >>"%REQ_ALL%" + del "!REQ_PKG!" "!REQ_PKG!.sorted" 2>nul + set "LIST_OUT=" +) + +set "REQ_PIP_FLAGS=install" +set "CNT=0" +for /f "usebackq delims=" %%F in ("%REQ_ALL%") do call :add_one_req "%%F" + +if !CNT! equ 0 ( + echo Nothing to install - no requirements files found. + del "%REQ_ALL%" 2>nul + exit /b 0 +) + +echo. +echo Requirements files used ^(!CNT! total^), in pip order: +set "LI=0" +for /f "usebackq delims=" %%F in ("%REQ_ALL%") do call :log_req_line "%%F" +echo. +echo Running pip install with all -r files above. +"%PY%" -m pip !REQ_PIP_FLAGS! +set "RC=!ERRORLEVEL!" +del "%REQ_ALL%" 2>nul +exit /b !RC! + +:log_req_line +if not exist "%~1" exit /b 0 +set /a LI+=1 +echo !LI!. %~1 +exit /b 0 + +:add_one_req +if not exist "%~1" exit /b 0 +for %%I in ("%~1") do set "REQ_PIP_FLAGS=!REQ_PIP_FLAGS! -r %%I" +set /a CNT+=1 +exit /b 0 + +:append_if_not_blacklisted +set "OBPATH=%~1" +for %%B in (%PKG_IGNORE_DIRS%) do call :path_under_blacklisted_pkg "%%B" && exit /b 0 +>>"%LIST_OUT%" echo(!OBPATH! +exit /b 0 + +:path_under_blacklisted_pkg +call set "T=%%OBPATH:\packages\%~1\=%%" +if not "!T!"=="!OBPATH!" exit /b 0 +exit /b 1 diff --git a/install_scripts/install_all_dependencies.sh b/install_scripts/install_all_dependencies.sh new file mode 100644 index 0000000000..4bbbac5843 --- /dev/null +++ b/install_scripts/install_all_dependencies.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Install Python dependencies from requirements files at the OctoBot repo root +# and under OctoBot/packages (any subdirectory). +# Ignores requirement files under packages// for each name in PACKAGES_IGNORE_DIRS. +# dev_requirements.txt under packages/ is ignored; repo root dev_requirements.txt is used. +# One pip install with multiple -r flags. + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +OCTOBOT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +PACKAGES_DIR="$OCTOBOT_ROOT/packages" + +# Basenames under packages/ to skip (blacklist). Example: (binary other_pkg) +PACKAGES_IGNORE_DIRS=(binary) + +packages_path_is_blacklisted() { + local f="$1" + local d + for d in "${PACKAGES_IGNORE_DIRS[@]}"; do + if [[ "$f" == *"/packages/${d}/"* ]]; then + return 0 + fi + done + return 1 +} + +if command -v python3 >/dev/null 2>&1; then + PIP=(python3 -m pip) +elif command -v python >/dev/null 2>&1; then + PIP=(python -m pip) +else + echo "error: neither python3 nor python found in PATH" >&2 + exit 1 +fi + +req_files=() +for name in full_requirements.txt requirements.txt dev_requirements.txt; do + path="$OCTOBOT_ROOT/$name" + if [[ -f "$path" ]]; then + req_files+=("$path") + fi +done + +if [[ -d "$PACKAGES_DIR" ]]; then + while IFS= read -r file; do + [[ -n "$file" ]] || continue + if packages_path_is_blacklisted "$file"; then + continue + fi + req_files+=("$file") + done < <( + find "$PACKAGES_DIR" -type f \( \ + -name full_requirements.txt -o \ + -name requirements.txt \ + \) -print | LC_ALL=C sort + ) +fi + +if [[ ${#req_files[@]} -eq 0 ]]; then + echo "Nothing to install (no requirements files found)." + exit 0 +fi + +echo "" +echo "Requirements files used (${#req_files[@]} total), in pip order:" +i=1 +for f in "${req_files[@]}"; do + printf ' %2d. %s\n' "$i" "$f" + i=$((i + 1)) +done +echo "" +echo "Running pip install with all -r files above." +args=() +for f in "${req_files[@]}"; do + args+=(-r "$f") +done +"${PIP[@]}" install "${args[@]}"