File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ lite-ext:
3535
3636lite-build :
3737 rm -rf .jupyterlite.doit.db caterva2/services/static/jupyterlite
38- ${BIN} /jupyter lite build --output-dir caterva2/services/static/jupyterlite
38+ # --lite-dir points at the in-package jupyter-lite.json (contentsAllJsonFile),
39+ # so the build picks it up regardless of the working directory (the deploy
40+ # builds from elsewhere). See caterva2/services/lite-config/.
41+ ${BIN} /jupyter lite build --lite-dir caterva2/services/lite-config --output-dir caterva2/services/static/jupyterlite
3942
4043# Installs our jupyterlite fork from a local copy, for development purposes
4144# Before doing this you must run "make build" in our jupyterlite fork
Original file line number Diff line number Diff line change @@ -44,9 +44,13 @@ def inject_pyodide_bootstrap_cell(content: bytes) -> bytes:
4444 except Exception :
4545 return content
4646
47- for cell in notebook .cells :
48- if cell .get ("metadata" , {}).get ("caterva2_pyodide_bootstrap" ):
49- return content
47+ # Drop any previously-injected bootstrap cell(s) and prepend a fresh one, so a
48+ # served notebook always carries the *current* bootstrap source. A stale cell may
49+ # have been baked into the saved file (e.g. persisted by save-back, or shipped in
50+ # the notebook); skipping when one exists would keep serving outdated install code.
51+ notebook .cells = [
52+ cell for cell in notebook .cells if not cell .get ("metadata" , {}).get ("caterva2_pyodide_bootstrap" )
53+ ]
5054
5155 bootstrap_cell = nbformat .v4 .new_code_cell (PYODIDE_BOOTSTRAP_CELL_SOURCE )
5256 bootstrap_cell ["metadata" ]["caterva2_pyodide_bootstrap" ] = True
Original file line number Diff line number Diff line change 11import nbformat
22
3- from caterva2 .services .notebook import inject_pyodide_bootstrap_cell
3+ from caterva2 .services .notebook import PYODIDE_BOOTSTRAP_CELL_SOURCE , inject_pyodide_bootstrap_cell
44
55
66def _bootstrap_cells (notebook ):
@@ -27,3 +27,19 @@ def test_inject_pyodide_bootstrap_cell_is_idempotent():
2727 patched_notebook = nbformat .reads (patched_twice .decode ("utf-8" ), as_version = 4 )
2828
2929 assert len (_bootstrap_cells (patched_notebook )) == 1
30+
31+
32+ def test_inject_pyodide_bootstrap_cell_refreshes_stale_cell ():
33+ # A notebook with an OUTDATED bootstrap cell baked in (e.g. persisted by an
34+ # older server / save-back) must be refreshed to the current source, not skipped.
35+ stale = nbformat .v4 .new_code_cell ("# old install code\n await micropip.install('blosc2')" )
36+ stale ["metadata" ]["caterva2_pyodide_bootstrap" ] = True
37+ notebook = nbformat .v4 .new_notebook (cells = [stale , nbformat .v4 .new_code_cell ("print('hello')" )])
38+ content = nbformat .writes (notebook ).encode ("utf-8" )
39+
40+ patched_notebook = nbformat .reads (inject_pyodide_bootstrap_cell (content ).decode ("utf-8" ), as_version = 4 )
41+
42+ bootstrap = _bootstrap_cells (patched_notebook )
43+ assert len (bootstrap ) == 1
44+ assert patched_notebook .cells [0 ]["metadata" ]["caterva2_pyodide_bootstrap" ] is True
45+ assert patched_notebook .cells [0 ].source == PYODIDE_BOOTSTRAP_CELL_SOURCE
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments