Skip to content

Commit 0b206d4

Browse files
feat(mac-launcher): auto-discover an mlx_lm-capable Python (no manual KAKEYA_MAC_PYTHON needed)
After a reboot / in a fresh shell the bare 'python3' is often the system/pyenv one without mlx_lm, so the launcher's preflight failed ('mlx/mlx_lm not importable by python3'). Now the launcher tries KAKEYA_MAC_PYTHON -> repo .venv-mac -> ~/kakeya-venv -> ~/.venv -> python3.13 -> python3 and picks the FIRST that can 'import mlx_lm' (logs which). Only fails fast (with the searched candidates listed) when none exists. bash 3.2-safe. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
1 parent 5c1bc29 commit 0b206d4

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

scripts/run_kakeya_mac.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,33 @@ done
6464

6565
log() { echo "[run-kakeya-mac] $*" >&2; }
6666

67-
# Pinned interpreter (Layer B): prefer KAKEYA_MAC_PYTHON (the venv python with
68-
# mlx_lm/torch/transformers) over a bare python3 that a host reboot may have
69-
# repointed. See docs/skills/pin-selfhosted-runner-python-env-skill.md.
70-
PYBIN="${KAKEYA_MAC_PYTHON:-python3}"
67+
# Pinned interpreter (Layer B): AUTO-DISCOVER the venv python that actually has
68+
# mlx_lm (a bare `python3` is often the system/pyenv one without it, especially
69+
# after a reboot or in a fresh shell). Try KAKEYA_MAC_PYTHON first, then common
70+
# venv locations, then PATH pythons; pick the first that can `import mlx_lm`.
71+
# Set KAKEYA_MAC_PYTHON to override. See
72+
# docs/skills/pin-selfhosted-runner-python-env-skill.md.
73+
_can_import_mlx_lm() { [ -n "${1:-}" ] && "$1" -c 'import mlx_lm' >/dev/null 2>&1; }
74+
_resolve_pybin() {
75+
local c
76+
for c in \
77+
"${KAKEYA_MAC_PYTHON:-}" \
78+
"$repo_root/.venv-mac/bin/python3.13" \
79+
"$repo_root/.venv-mac/bin/python" \
80+
"$repo_root/.venv/bin/python" \
81+
"$HOME/kakeya-venv/bin/python" \
82+
"$HOME/.venv/bin/python" \
83+
"$(command -v python3.13 2>/dev/null || true)" \
84+
"$(command -v python3 2>/dev/null || true)"; do
85+
if _can_import_mlx_lm "$c"; then printf '%s' "$c"; return 0; fi
86+
done
87+
# Nothing with mlx_lm — fall back to a sensible value so dry-run/preflight can
88+
# still report a clear error.
89+
printf '%s' "${KAKEYA_MAC_PYTHON:-python3}"
90+
return 1
91+
}
92+
PYBIN="$(_resolve_pybin)" || true
93+
log "python : $PYBIN$([ -n "${KAKEYA_MAC_PYTHON:-}" ] && echo ' (KAKEYA_MAC_PYTHON)')"
7194

7295
# ---- argv for the full-engine harness chat ----
7396
args=(
@@ -107,9 +130,11 @@ if [[ "$DRY_RUN" == "1" ]]; then
107130
fi
108131

109132
# ---- preflight (Apple Silicon + MLX + model) ----
110-
command -v "$PYBIN" >/dev/null 2>&1 || { log "interpreter not found: $PYBIN (set KAKEYA_MAC_PYTHON)"; exit 1; }
111133
"$PYBIN" -c "import mlx.core, mlx_lm" 2>/dev/null \
112-
|| { log "mlx/mlx_lm not importable by $PYBIN — Apple Silicon + a venv with 'mlx mlx-lm'; set KAKEYA_MAC_PYTHON. See docs/skills/pin-selfhosted-runner-python-env-skill.md"; exit 2; }
134+
|| { log "no Python with mlx_lm found (auto-searched KAKEYA_MAC_PYTHON, "\
135+
"$repo_root/.venv-mac, ~/kakeya-venv, ~/.venv, python3.13, python3; tried '$PYBIN'). "\
136+
"Activate your MLX venv or set KAKEYA_MAC_PYTHON=/path/to/venv/bin/python "\
137+
"(needs 'mlx mlx-lm torch transformers'). See docs/skills/pin-selfhosted-runner-python-env-skill.md"; exit 2; }
113138
[[ -d "$VERIFIER" ]] \
114139
|| { log "verifier model dir not found: $VERIFIER (set KAKEYA_MAC_VERIFIER_PATH)"; exit 3; }
115140
if [[ "$FAST" != "1" && ! -e "$FTHETA" ]]; then

0 commit comments

Comments
 (0)