Skip to content

Commit 112dd92

Browse files
committed
Don't auto-execute if prompt numbers are present
See #41.
1 parent ae50ed1 commit 112dd92

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

nbsphinx.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,14 @@ def from_notebook_node(self, nb, resources=None, **kw):
455455
execute = nbsphinx_metadata.get('execute', self._execute)
456456
if execute not in ('always', 'never', 'auto'):
457457
raise NotebookError('invalid execute option: {!r}'.format(execute))
458-
# Auto-execute notebook only if there are code cells and no outputs:
459-
no_outputs = (
460-
any(c.source for c in nb.cells if c.cell_type == 'code') and not
461-
any(c.outputs for c in nb.cells if 'outputs' in c))
462-
if execute == 'always' or (execute == 'auto' and no_outputs):
458+
auto_execute = (
459+
# At least one code cell actually containing source code:
460+
any(c.source for c in nb.cells if c.cell_type == 'code') and
461+
# No outputs, not even a prompt number:
462+
not any(c.get('outputs') or c.get('execution_count')
463+
for c in nb.cells if c.cell_type == 'code')
464+
)
465+
if execute == 'always' or (execute == 'auto' and auto_execute):
463466
allow_errors = nbsphinx_metadata.get(
464467
'allow_errors', self._allow_errors)
465468
timeout = nbsphinx_metadata.get('timeout', self._timeout)

0 commit comments

Comments
 (0)