#!/usr/bin/env bash
set -euo pipefail

if command -v uv >/dev/null 2>&1; then
  exec uv run "$@"
fi

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

if ! "$python_bin" -m pip --version >/dev/null 2>&1; then
  "$python_bin" -m ensurepip --upgrade
fi

marker=".venv/.gewu-dev-installed"
if [[ ! -f "$marker" ]]; then
  "$python_bin" -m pip install --disable-pip-version-check -e '.[dev]'
  touch "$marker"
fi

tool="$1"
shift
exec ".venv/bin/$tool" "$@"
