#!/usr/bin/env bash
# Installation, not PYTHONPATH ordering, selects the in-repository packages.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ -n "${MJLAB_ROOT:-}" || -n "${UH_EXTRA_PYTHONPATH:-}" ]]; then
  echo 'External backend/PYTHONPATH overrides are no longer supported. Install this repository; see docs/SETUP.md.' >&2
  exit 1
fi
if [[ -n "${UH_PYTHON:-}" ]]; then
  PY="$UH_PYTHON"
elif [[ -x "$ROOT/.venv/bin/python" ]]; then
  PY="$ROOT/.venv/bin/python"
else
  PY="$(command -v python3 || true)"
fi
if [[ ! -x "$PY" ]]; then
  echo 'Invalid Python interpreter. Run uv sync --locked --extra dev, or set UH_PYTHON explicitly.' >&2
  exit 1
fi
# Exclude unrelated ROS/site configuration without injecting source directories.
unset PYTHONPATH
export PYTHONNOUSERSITE=1
export MUJOCO_GL="${MUJOCO_GL:-egl}"
export OMP_NUM_THREADS="${OMP_NUM_THREADS:-4}"
exec "$PY" -m universal_humanoid "$@"
