#!/usr/bin/env bash
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$HERE"
PY="${PYTHON:-../../../.venv/bin/python}"
export PYTHONUNBUFFERED=1
export OMP_NUM_THREADS="${OMP_NUM_THREADS:-4}"
export SCORE_JOBS="${SCORE_JOBS:-2}"
# Every child inherits stdout/stderr. Tee is the only file logger.
{
  printf '\n========== V2 RUN %s ==========\n' "$(date -Is)"
  printf 'Python: %s\n' "$PY"
  if "$PY" -u run_all.py "$@"; then rc=0; else rc=$?; fi
  printf '========== V2 EXIT rc=%s %s ==========\n' "$rc" "$(date -Is)"
  exit "$rc"
} 2>&1 | tee -a "$HERE/v2.log"
