Skip to content

Code cells inside ANY directive never execute in the browser (exercise, solution, note) #64

Description

@mmcky

short_path cannot be completed by a reader on the live site. The cell that loads the graph never executes, so every later cell raises NameError. This predates any recent change.

What a reader sees

Click through the cells in order and the final one fails:

NameError: name 'graph_file_data' is not defined
Cell In[7], line 1
----> 1 Q = map_graph_to_distance_matrix(graph_file_data)

The execution counter is the tell: In[7] for a cell at document position #8 on a 9-cell page. Exactly one preceding cell never ran.

Why

myst build nests code cells inside directives, and thebe only wires up cells at the top-level block layer. From the published short-path.json:

cell ancestry runs?
import numpy as np ['root','block']
from numpy import inf ['root','block']
nodes = range(7) ['root','block']
the graph data cell ['root','block','exercise','block']
num_nodes = 100 … and the rest ['root','block']

On main two cells are nested there — import requests and graph_file_data = str(graph_file_response.content, 'utf-8') — so the data is never fetched and never assigned.

The part that makes this subtle: a second bug is currently masking a worse version of the first

short_path.md:480 is a bare ```{solution} used as a closer. mystmd rejects it:

mystDirectiveError  line 480
"required argument not provided for directive: solution"

The opener at :381 is {solution} too, where lecture-python-intro — and every other repo carrying this lecture — uses the gated pair {solution-start} / {solution-end}.

Because that directive is unbalanced, the solution node in the AST is empty (its only child is admonitionTitle) and all of the solution's content spills out into top-level blocks. That accident is load-bearing: the spilled cells are the ones a reader can actually run.

Fixing the directive to the gated form — the obvious correct change — was tried on a branch and rebuilt. It removes the error, but the solution's five cells then correctly nest as ['block','solution','block'], i.e. the fix would likely take this lecture from one dead cell to six. So the two bugs must be addressed together, and the directive must not be "tidied up" on its own.

What to decide

  1. Is nesting genuinely what stops execution? Strongly implied by the correlation, but not yet isolated — worth confirming, and worth raising upstream with mystmd/thebe if gated directives are meant to keep code cells runnable. The gated -start/-end forms exist precisely so executable content can live at the root level, so this may be a genuine upstream defect rather than intended behaviour.
  2. If it is, the graph data cell needs to sit outside {exercise-start}{exercise-end}, which is a small content decision — the exercise prose says "The text below describes a weighted directed graph" and the solution says "reads in the graph data above", so moving it needs a sentence adjusted.
  3. Only then fix the {solution} directive.

Scope

This is independent of the dataset migration. #63 removes this lecture's cross-repo fetch of lecture-python-intro's committed graph.txt and is neutral on the problem here: it goes from two nested dead cells to one, and does not make the lecture runnable. That is why it is not being merged as a fix for this.

Worth checking whether other lectures here put code cells inside {exercise} blocks — this may not be the only one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions