#!/usr/bin/env bash
# Create/use project venv and install requirements (PEP 668 safe).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

VENV="${ROOT}/.venv"
PY="${VENV}/bin/python3"
PIP="${VENV}/bin/pip"

if [[ ! -x "$PY" ]]; then
  echo "Creating .venv ..."
  python3 -m venv "$VENV"
fi

"$PIP" install -q -U pip
"$PIP" install -q -r requirements.txt
"$PIP" install -q pytest pytest-asyncio
echo "[OK] venv ready: $PY ($("$PY" -c 'import sqlalchemy,redis; print("sqlalchemy", sqlalchemy.__version__, "redis", redis.__version__)'))"
