#!/usr/bin/env bash
set -eu

client_root="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
python_bin="${PYTHON:-python3}"

if ! command -v "$python_bin" >/dev/null 2>&1; then
  echo "Python 3.11 or newer is required. Install Python, then run this launcher again." >&2
  exit 1
fi

venv_root="$client_root/.venv"
venv_python="$venv_root/bin/python"
if [ ! -x "$venv_python" ]; then
  "$python_bin" -m venv "$venv_root"
fi

"$venv_python" -m pip install --disable-pip-version-check --quiet -r "$client_root/requirements.txt"
exec "$venv_python" "$client_root/silo_desktop.py" "$@"
