#!/usr/bin/env bash set -euo pipefail root=${1:?Usage: Setup-Python.sh APPLICATION_DIRECTORY [--sam2]} root=$(cd "$root" && pwd) bootstrap=${PYTHON:-python3} "$bootstrap" -c 'import sys; assert sys.version_info >= (3, 10), "Python 3.10 or later is required; Python 3.12 is recommended"' # Resolve deployment symlinks so venv entry points do not depend on an old release directory. runtime=$(realpath -m "${SOPHELPER_PYTHON_ROOT:-$root/python}") "$bootstrap" -m venv "$runtime" python="$runtime/bin/python3" "$python" -m pip install --upgrade pip "$python" -m pip install 'torch>=2.5.1' torchvision --index-url https://download.pytorch.org/whl/cpu "$python" -m pip install -r "$root/tools/requirements.txt" if [ "${2:-}" = --sam2 ]; then "$python" -m pip install setuptools wheel huggingface_hub SAM2_BUILD_CUDA=0 "$python" -m pip install --no-build-isolation 'git+https://github.com/facebookresearch/sam2.git@2b90b9f5ceec907a1c18123530e92e794ad901a4' fi printf 'Python runtime ready: %s\n' "$python"