#!/usr/bin/env bash
set -e
cd "$(dirname "$0")"
APP_FILE="beanalyzer_ultrapro.py"
VENV_DIR=".venv"
find_python() {
  if command -v python3.12 >/dev/null 2>&1; then echo python3.12; return; fi
  if command -v python3.13 >/dev/null 2>&1; then echo python3.13; return; fi
  if command -v python3 >/dev/null 2>&1; then echo python3; return; fi
  if command -v python >/dev/null 2>&1; then echo python; return; fi
}
PYTHON_BIN="$(find_python)"
if [ -z "$PYTHON_BIN" ]; then echo "Python not found. Install Python 3.12."; exit 1; fi
if [ ! -f "$APP_FILE" ]; then echo "$APP_FILE not found. Put this launcher in the project folder."; exit 1; fi
if [ ! -d "$VENV_DIR" ]; then "$PYTHON_BIN" -m venv "$VENV_DIR"; fi
source "$VENV_DIR/bin/activate"
python --version
python -m ensurepip --upgrade >/dev/null 2>&1 || true
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt
python "$APP_FILE"
