Commit dab29fc
authored
ci(run-notebook): replace whole-cell bash partition with nbclient (#573)
## Purpose
The current `run-notebook` action partitions each code cell whole-cell:
cells containing `!pip` go entirely to a bash script, the rest go to a
Python script. A cell that mixes `!pip install` with Python imports — a
standard Jupyter pattern — fails with `import: command not found`
because bash tries to execute Python as a shell command. See PR #572 /
[run
25743389812](https://github.com/pinecone-io/examples/actions/runs/25743389812/job/75599935724)
for a live example.
## Solution
Drive notebooks through [`nbclient`](https://nbclient.readthedocs.io/),
the same tool Project Jupyter ships behind `jupyter nbconvert
--execute`. `nbclient` launches a real `ipykernel` and processes cells
line-by-line: `!pip` and other shell magics route through the kernel's
magic handlers (subshell), Python runs as Python. Mixed cells work
exactly as they do in Colab and Jupyter Lab.
## Changes
- New `run-notebook.py`: 50-line nbclient driver. Takes the notebook
path as its only arg. Exits 0 on success, 1 on any cell error, 2 on
usage error.
- Updated `action.yml`: installs `nbformat nbclient ipykernel` into the
runner Python, then invokes the new script. No tempdir, no nested venv,
no bash conversion.
- Removed `convert-notebook.py` (~120 lines).
Net diff: 66 insertions, 137 deletions.
## Verification
Tested locally against the notebook from PR #572
(`docs/quick-tour/hello-pinecone.ipynb`, with `!pip install` and Python
imports in the same cell — the case that breaks today's runner):
```
$ python .github/actions/run-notebook/run-notebook.py docs/quick-tour/hello-pinecone.ipynb
Executing docs/quick-tour/hello-pinecone.ipynb
PASS — docs/quick-tour/hello-pinecone.ipynb
```
## Notes
- **`check-structure` follow-up.** The lint rule "imports must be in the
first code cell" was designed around today's runner: under the new
runner, a single cell holding `!pip install` + imports is once again the
correct pattern. Either relax the rule to skip pip-only cells when
locating "the first code cell," or remove the rule entirely. Separate
PR.
- **Notebook dep isolation.** Notebook deps now install into the
runner's Python (the kernel shares its interpreter), not a nested venv.
Acceptable for CI (ephemeral runner) and simpler than the previous
tempdir/venv dance.
- **Per-cell timeout.** 600s by default, overridable via
`NOTEBOOK_CELL_TIMEOUT`.
- **Soak.** Worth running this against a known-passing notebook before
merging to confirm no regressions on the existing fleet — let me know if
you want me to dual-run on a sample.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes the CI notebook execution mechanism from a custom
conversion/venv+bash flow to `nbclient` driving a real Jupyter kernel,
which may alter dependency/runtime behavior and failure modes across the
notebook suite.
>
> **Overview**
> Updates the `run-notebook` composite action to execute notebooks
end-to-end using `nbclient`/`ipykernel` instead of converting cells into
separate bash/python scripts.
>
> This removes `convert-notebook.py`, installs `nbformat nbclient
ipykernel` on the runner, and adds `run-notebook.py` which runs the
notebook with a real kernel, returning clearer per-cell errors and
supporting mixed `!pip` + Python cells (with an optional
`NOTEBOOK_CELL_TIMEOUT`).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f87187a. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent e01abf7 commit dab29fc
3 files changed
Lines changed: 78 additions & 137 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | | - | |
38 | 37 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 38 | + | |
55 | 39 | | |
56 | 40 | | |
57 | 41 | | |
58 | 42 | | |
59 | | - | |
| 43 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments