Skip to content

Commit b304829

Browse files
committed
make output to stderr print a warning, rather than raise an exception
Sphinx warnings can still be turned into exceptions with -W. Closes #72.
1 parent 9101ee3 commit b304829

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

jupyter_sphinx/execute.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ def apply(self):
379379
if output['output_type'] == 'stream'
380380
and output['name'] == 'stderr']
381381
if stderr and not node.attributes['stderr']:
382-
raise ExtensionError('Cell printed to stderr:\n{}'
383-
.format(stderr[0]['text']))
382+
logger.warning('Cell printed to stderr:\n{}'
383+
.format(stderr[0]['text']))
384384

385385
try:
386386
lexer = notebook.metadata.language_info.pygments_lexer
@@ -407,6 +407,7 @@ def apply(self):
407407
output_nodes = cell_output_to_nodes(
408408
cell,
409409
self.config.jupyter_execute_data_priority,
410+
bool(node.attributes["stderr"]),
410411
sphinx_abs_dir(self.env),
411412
thebe_config
412413
)
@@ -463,14 +464,16 @@ def count(x):
463464
return (list(x) for _, x in groupby(it, count))
464465

465466

466-
def cell_output_to_nodes(cell, data_priority, dir, thebe_config):
467+
def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
467468
"""Convert a jupyter cell with outputs and filenames to doctree nodes.
468469
469470
Parameters
470471
----------
471472
cell : jupyter cell
472473
data_priority : list of mime types
473474
Which media types to prioritize.
475+
write_stderr : bool
476+
If True include stderr in cell output
474477
dir : string
475478
Sphinx "absolute path" to the output folder, so it is a relative path
476479
to the source folder prefixed with ``/``.
@@ -483,6 +486,8 @@ def cell_output_to_nodes(cell, data_priority, dir, thebe_config):
483486
if (
484487
output_type == 'stream'
485488
):
489+
if not write_stderr and output["name"] == "stderr":
490+
continue
486491
to_add.append(docutils.nodes.literal_block(
487492
text=output['text'],
488493
rawsource=output['text'],

0 commit comments

Comments
 (0)