summaryrefslogtreecommitdiff
path: root/bin/pyexec
blob: 303bc4b8a841f933dca2a4ab81ae2c8e08533232 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

set -euo pipefail

debug() {
  if [[ "${DEBUG:-}" == "pyexec" ]]; then
    >&2 echo "[DEBUG=pyexec]" "$@"
  fi
}

if [[ -n "${VIRTUAL_ENV:-}" ]]; then
  debug "Detected VIRTUAL_ENV"
  i=python
elif [[ -r ".venv/bin/activate" ]]; then
  debug "Found .venv, activating"
  source .venv/bin/activate
  i=python
elif command -v python3 >/dev/null; then
  debug "Found python3 in path"
  i=python3
else
  debug "Defaulting to python"
  i=python
fi

exec "$i" "$@"