Skip to content

Commit fa17adc

Browse files
authored
Merge pull request #496 from neuromatch/jupyter-book-2
fix: add skip-execution tag to NotImplementedError stub cells for JB2…
2 parents 5eaaa3a + 5fef812 commit fa17adc

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

generate_book_v2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,31 @@ def pre_process_notebook(file_path):
235235
content = open_in_colab_new_tab(content)
236236
content = change_video_widths(content)
237237
content = link_hidden_cells(content)
238+
content = tag_stub_cells(content)
238239
with open(file_path, "w", encoding="utf-8") as fh:
239240
json.dump(content, fh, indent=1, ensure_ascii=False)
240241

241242

243+
def tag_stub_cells(content):
244+
"""Add skip-execution tag to cells containing raise NotImplementedError.
245+
246+
JB1 used allow_errors:true to silently swallow errors from these stub cells.
247+
JB2 has no global equivalent, so we skip execution instead — the source is
248+
still rendered (students see the stub), but no error traceback is produced.
249+
"""
250+
for cell in content["cells"]:
251+
if cell["cell_type"] != "code":
252+
continue
253+
if any("NotImplementedError" in s for s in cell.get("source", [])):
254+
if "metadata" not in cell:
255+
cell["metadata"] = {}
256+
if "tags" not in cell["metadata"]:
257+
cell["metadata"]["tags"] = []
258+
if "skip-execution" not in cell["metadata"]["tags"]:
259+
cell["metadata"]["tags"].append("skip-execution")
260+
return content
261+
262+
242263
def open_in_colab_new_tab(content):
243264
cells = content["cells"]
244265
if not cells or not cells[0].get("source"):

0 commit comments

Comments
 (0)