CausalGrok / code /scripts /lib /env.sh
nileshsarkar-ai's picture
Upload code/scripts
42c0d23 verified
#!/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
}