#!/usr/bin/env bash set -euo pipefail repo_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" if [[ -n "${PYTHON:-}" ]]; then python_bin="$PYTHON" elif [[ -n "${VIRTUAL_ENV:-}" && -x "$VIRTUAL_ENV/bin/python" ]]; then python_bin="$VIRTUAL_ENV/bin/python" elif [[ -x "$repo_dir/.venv/bin/python" ]]; then python_bin="$repo_dir/.venv/bin/python" else python_bin=python3 fi if ! command -v "$python_bin" >/dev/null 2>&1; then printf 'Python not found. Install Python 3.12+ and dependencies; see README.md.\n' >&2 exit 127 fi # Allow invocation outside the repository without an editable package install. export PYTHONPATH="$repo_dir/src${PYTHONPATH:+:$PYTHONPATH}" # Parsed as literal settings by Python; never sourced/executed as shell code. export ARCHIVE_ENV_FILE="${ARCHIVE_ENV_FILE:-$repo_dir/.env}" # argparse requires --mode, validates --max-weeks, and rejects unknown options. exec "$python_bin" -m btcdata_archive run "$@"