Skip to content

Commit 3bf0b14

Browse files
authored
Handle missing notebook metadata file_extension
1 parent 6a0df85 commit 3bf0b14

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

jupyter_sphinx/execute.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,15 @@ def write_notebook_output(notebook, output_dir, notebook_name):
257257
os.path.join(output_dir, notebook_name + ".ipynb"),
258258
)
259259
# Write a script too.
260-
ext = notebook.metadata.language_info.file_extension
260+
if ntbk.metadata.get("language_info", {}).get("file_extension", None) is None:
261+
ext = ".txt"
262+
js.logger.warning(
263+
"Notebook code has no file extension metadata, " "defaulting to `.txt`",
264+
# TODO correct location
265+
# location=document.settings.env.docname,
266+
)
267+
else:
268+
ext = notebook.metadata.language_info.file_extension
261269
contents = "\n\n".join(cell.source for cell in notebook.cells)
262270
with open(os.path.join(output_dir, notebook_name + ext), "w") as f:
263271
f.write(contents)

0 commit comments

Comments
 (0)