Files
computer-playbook/scripts/meta/python/detect.sh
T
kevinveenbirkenbachandClaude Opus 4.7 165fb9cc89 fix(meta/python/detect): probe /opt writability, not /opt/venvs existence
Virgin pkgmgr containers ship without /opt/venvs, so the prior
'-d /opt/venvs && -w /opt/venvs' check fell through to ${HOME}/.venvs,
breaking the test-install-{make,pkgmgr} workflows that hardcode
'source /opt/venvs/infinito/bin/activate'. Probe the parent instead —
venv.sh mkdir -p's the leaf later.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 00:56:37 +02:00

34 lines
809 B
Bash
Executable File

#!/usr/bin/env bash
# shellcheck shell=bash
#
# SPOT for venv + Python interpreter resolution. Exports VENV, PYTHON,
# PIP, PYTHONPATH. Sourced; re-entrant.
VENV_NAME=infinito
if [[ -n "${VIRTUAL_ENV:-}" ]]; then
VENV_BASE="$(dirname "${VIRTUAL_ENV}")"
elif [[ -d /opt && -w /opt ]]; then
VENV_BASE=/opt/venvs
else
VENV_BASE="${HOME}/.venvs"
fi
VENV_FALLBACK="${VENV_BASE%/}/${VENV_NAME}"
VENV="${VENV:-${VIRTUAL_ENV:-${VENV_FALLBACK}}}"
if [[ -x "${VENV}/bin/python" ]]; then
PYTHON="${VENV}/bin/python"
elif command -v python3 >/dev/null 2>&1; then
PYTHON=python3
else
echo "detect.sh: no python3 on PATH and no venv at ${VENV}/bin/python" >&2
# shellcheck disable=SC2317
return 1 2>/dev/null || exit 1
fi
PIP="${PYTHON} -m pip"
PYTHONPATH="${PYTHONPATH:-.}"
export VENV PYTHON PIP PYTHONPATH