#!/bin/sh
# `python` for a woken session (2026-09-14:  a session found no interpreter and
# its test run read as a suite that collected nothing).  This folder is first on
# every woken session's PATH.
#
# A project's own virtual environment wins, because it is the one interpreter
# holding that project's dependencies:  the nearest .venv at or above the
# working folder.  Otherwise python3 from the PATH.  With neither, it says so
# rather than failing quietly.  Shell built-ins only, so it works on a PATH that
# has nothing else on it.
d="$PWD"
while [ -n "$d" ]; do
  if [ -x "$d/.venv/bin/python" ]; then exec "$d/.venv/bin/python" "$@"; fi
  [ "$d" = "/" ] && break
  d="${d%/*}"; [ -z "$d" ] && d="/"
done
self="${0%/*}"
old_ifs="$IFS"; IFS=:
for p in $PATH; do
  IFS="$old_ifs"
  [ "$p" = "$self" ] && continue
  if [ -x "$p/python3" ]; then exec "$p/python3" "$@"; fi
done
echo "python:  no Python is installed on this machine, so nothing ran.  Tell the core developer." >&2
exit 127
