Skip to content

Commit 183a562

Browse files
simontreanorclaude
andcommitted
kernel: resolve the pyfun binary from the kernel`s own env before PATH
Caught by verifying the released v0.0.8 wheel in a clean venv: with a stale global pyfun (pre-kernel-engine) shadowing the venv`s on PATH, shutil.which handed the kernel a binary without the protocol. Discovery order is now PYFUN_BIN -> sys.exec_prefix Scripts/bin -> PATH. Verified against the released wheel with the fix applied: install.py kernelspec + full cell session all pass; ROADMAP verification gaps updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SoP7DMAgjNCihZHsdBagYr
1 parent cdb8a66 commit 183a562

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

ROADMAP.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ dev machine. Close each by running the listed check once; delete its line when i
5151
- **Tree-sitter rendering**: captures are validated with `tree-sitter query`, but no themed
5252
highlight render (`tree-sitter highlight` needs a configured theme) and no `test/corpus/` golden
5353
trees — the gate is the zero-ERROR parse sweep + compiler-validated `test/stress.pyfun`.
54-
- **Jupyter kernel**: verified end-to-end via `jupyter_client` on Windows/CPython 3.14, but (a)
55-
`python -m pyfun_kernel.install` itself has never run (the e2e wrote its own dev kernelspec), (b)
56-
no real JupyterLab/Notebook UI session yet, (c) the engine-death replay path in `kernel.py` is
57-
code-reviewed only, (d) KeyboardInterrupt during a long cell untested, (e) macOS/Linux untested.
58-
The pip-installed `[jupyter]` extra + `install.py` path should be checked against the first wheel
59-
that ships the kernel (v0.0.8).
54+
- **Jupyter kernel**: verified end-to-end via `jupyter_client` on Windows/CPython 3.14 — including,
55+
against the released v0.0.8 wheel in a clean venv: the `[jupyter]` extra, `python -m
56+
pyfun_kernel.install --sys-prefix`, and a full cell session on the installed kernelspec. Still
57+
open: (a) no real JupyterLab/Notebook UI session yet, (b) the engine-death replay path in
58+
`kernel.py` is code-reviewed only, (c) KeyboardInterrupt during a long cell untested, (d)
59+
macOS/Linux untested. Known issue in the shipped 0.0.8 wheel (fixed in main, ships next tag):
60+
`kernel.py` resolved the `pyfun` binary via PATH before the kernel's own environment, so a stale
61+
global `pyfun` older than the kernel-engine protocol would break the kernel; discovery order is
62+
now PYFUN_BIN → same-env Scripts/bin → PATH.
6063

6164
## Non-goals (decided against — with the reason, so they're not re-litigated)
6265

python/pyfun_kernel/kernel.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,21 @@ def __init__(self):
4949

5050
@staticmethod
5151
def _binary():
52-
exe = os.environ.get("PYFUN_BIN") or shutil.which("pyfun")
52+
exe = os.environ.get("PYFUN_BIN")
53+
if exe:
54+
return exe
55+
# Prefer the binary installed alongside this interpreter (the wheel
56+
# puts it in Scripts/bin of the same environment) — a stale `pyfun`
57+
# elsewhere on PATH may predate the kernel-engine protocol.
58+
scripts = "Scripts" if os.name == "nt" else "bin"
59+
suffix = ".exe" if os.name == "nt" else ""
60+
local = os.path.join(sys.exec_prefix, scripts, "pyfun" + suffix)
61+
if os.path.exists(local):
62+
return local
63+
exe = shutil.which("pyfun")
5364
if not exe:
5465
raise EngineError(
55-
"cannot find the `pyfun` binary on PATH "
66+
"cannot find the `pyfun` binary in this environment or on PATH "
5667
"(pip install pyfun-lang); set PYFUN_BIN to override"
5768
)
5869
return exe

0 commit comments

Comments
 (0)