File size: 982 Bytes
42c0d23 | 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 28 29 30 31 32 | #!/usr/bin/env bash
# scripts/lib/env.sh
# Resolves which python to use, in priority order:
# 1. $PYTHON env var, if set
# 2. $CONDA_PREFIX/bin/python, if a conda env is active
# 3. ~/anaconda3/envs/causalgrok/bin/python, if it exists
# 4. system python, with a warning
#
# Source this; call `resolve_python` to set the global $PYTHON.
resolve_python() {
if [[ -n "${PYTHON:-}" ]] && [[ -x "${PYTHON}" ]]; then
return
fi
if [[ -n "${CONDA_PREFIX:-}" ]] && [[ -x "${CONDA_PREFIX}/bin/python" ]]; then
PYTHON="${CONDA_PREFIX}/bin/python"
return
fi
local cand="${HOME}/anaconda3/envs/causalgrok/bin/python"
if [[ -x "${cand}" ]]; then
PYTHON="${cand}"
return
fi
if command -v python >/dev/null 2>&1; then
PYTHON="$(command -v python)"
echo " warning: causalgrok env not found; using ${PYTHON}" >&2
return
fi
echo " error: no python interpreter found" >&2
return 1
}
|