Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No jupyter execution when not necessary #231

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions jupyter_sphinx/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def apply(self):
kernel_name = default_kernel
file_name = next(default_names)

# Save time when jupyter notebook execution is not necessary
if all("execute" in node and not node["execute"] for node in nodes):
notebook = blank_nb(kernel_name)
try:
cm_language = notebook.metadata.language_info.codemirror_mode.name
except AttributeError:
cm_language = notebook.metadata.kernelspec.language
# Mimic empty cell output for each node
for node in nodes:
source = node.children[0]
source.attributes["classes"].append("code_cell")
node.attributes["cm_language"] = cm_language
if len(node.children) < 2:
node += CellOutputNode(classes=["cell_output"])
apply_styling(node, thebe_config)
continue

# Add empty placeholder cells for non-executed nodes so nodes
# and cells can be zipped and the provided input/output
# can be inserted later
Expand Down