refactor: use delegated python binary in script execution and update resolution logic to prioritize virtual environments
This commit is contained in:
+11
-3
@@ -633,7 +633,9 @@ env_python() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
env "${envs[@]}" python3 - "$@"
|
local pybin
|
||||||
|
pybin="$(_delegate_py_bin)"
|
||||||
|
env "${envs[@]}" "$pybin" - "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -691,7 +693,9 @@ atomic_dump_yaml() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
local mutation; mutation="$(cat)"
|
local mutation; mutation="$(cat)"
|
||||||
env "${envs[@]}" AGENT_SESSIONS_MUTATION="$mutation" python3 - <<'PYEOF'
|
local pybin
|
||||||
|
pybin="$(_delegate_py_bin)"
|
||||||
|
env "${envs[@]}" AGENT_SESSIONS_MUTATION="$mutation" "$pybin" - <<'PYEOF'
|
||||||
import os, sys, tempfile, shutil, glob, subprocess, json, sqlite3
|
import os, sys, tempfile, shutil, glob, subprocess, json, sqlite3
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
import yaml
|
import yaml
|
||||||
@@ -1362,10 +1366,14 @@ PYEOF
|
|||||||
|
|
||||||
# _delegate_py_bin — echo the virtualenv python (walk up from .agents/skills/), else python3.
|
# _delegate_py_bin — echo the virtualenv python (walk up from .agents/skills/), else python3.
|
||||||
_delegate_py_bin() {
|
_delegate_py_bin() {
|
||||||
# Return cached result if available (shell variable, not exported — avoids cross-workspace pollution)
|
# Return cached result if available
|
||||||
if [ -n "${AGENT_PYTHON_BIN:-}" ] && [ -x "$AGENT_PYTHON_BIN" ]; then
|
if [ -n "${AGENT_PYTHON_BIN:-}" ] && [ -x "$AGENT_PYTHON_BIN" ]; then
|
||||||
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
|
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
|
||||||
fi
|
fi
|
||||||
|
if [ -n "${VIRTUAL_ENV:-}" ] && [ -x "$VIRTUAL_ENV/bin/python" ]; then
|
||||||
|
AGENT_PYTHON_BIN="$VIRTUAL_ENV/bin/python"
|
||||||
|
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
|
||||||
|
fi
|
||||||
local d
|
local d
|
||||||
d="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
d="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
while [ "$d" != "/" ] && [ -n "$d" ]; do
|
while [ "$d" != "/" ] && [ -n "$d" ]; do
|
||||||
|
|||||||
Reference in New Issue
Block a user