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

Handle missing notebook metadata file_extension #127

Merged
merged 4 commits into from
Jun 28, 2020
Merged
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion jupyter_sphinx/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,15 @@ def write_notebook_output(notebook, output_dir, notebook_name):
os.path.join(output_dir, notebook_name + ".ipynb"),
)
# Write a script too.
ext = notebook.metadata.language_info.file_extension
if ntbk.metadata.get("language_info", {}).get("file_extension", None) is None:
ext = ".txt"
js.logger.warning(
"Notebook code has no file extension metadata, " "defaulting to `.txt`",
# TODO correct location
# location=document.settings.env.docname,
chrisjsewell marked this conversation as resolved.
Show resolved Hide resolved
)
else:
ext = notebook.metadata.language_info.file_extension
chrisjsewell marked this conversation as resolved.
Show resolved Hide resolved
contents = "\n\n".join(cell.source for cell in notebook.cells)
with open(os.path.join(output_dir, notebook_name + ext), "w") as f:
f.write(contents)
Expand Down