Skip to content

Commit ec69f50

Browse files
committed
Add option to pass arguments to kernel when executing
1 parent 112dd92 commit ec69f50

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

doc/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# Default language for syntax highlighting in reST and Markdown cells
1717
highlight_language = 'none'
1818

19+
# List of arguments to be passed to the kernel that executes the notebooks:
20+
#nbsphinx_execute_arguments = ['--InlineBackend.figure_formats={"png", "pdf"}']
21+
1922
# -- These set defaults that can be overridden through notebook metadata --
2023

2124
# See http://nbsphinx.readthedocs.org/en/latest/allow-errors.html

nbsphinx.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,11 @@ class Exporter(nbconvert.RSTExporter):
424424
425425
"""
426426

427-
def __init__(self, execute='auto', allow_errors=False, timeout=30,
428-
codecell_lexer='none'):
427+
def __init__(self, execute='auto', execute_arguments=[],
428+
allow_errors=False, timeout=30, codecell_lexer='none'):
429429
"""Initialize the Exporter."""
430430
self._execute = execute
431+
self._execute_arguments = execute_arguments
431432
self._allow_errors = allow_errors
432433
self._timeout = timeout
433434
self._codecell_lexer = codecell_lexer
@@ -467,6 +468,7 @@ def from_notebook_node(self, nb, resources=None, **kw):
467468
'allow_errors', self._allow_errors)
468469
timeout = nbsphinx_metadata.get('timeout', self._timeout)
469470
pp = nbconvert.preprocessors.ExecutePreprocessor(
471+
extra_arguments=self._execute_arguments,
470472
allow_errors=allow_errors, timeout=timeout)
471473
nb, resources = pp.preprocess(nb, resources)
472474

@@ -512,10 +514,13 @@ def parse(self, inputstring, document):
512514
resources['output_files_dir'] = os.path.relpath(auxdir, srcdir)
513515
resources['unique_key'] = env.docname.replace('/', '_')
514516

515-
exporter = Exporter(execute=env.config.nbsphinx_execute,
516-
allow_errors=env.config.nbsphinx_allow_errors,
517-
timeout=env.config.nbsphinx_timeout,
518-
codecell_lexer=env.config.nbsphinx_codecell_lexer)
517+
exporter = Exporter(
518+
execute=env.config.nbsphinx_execute,
519+
execute_arguments=env.config.nbsphinx_execute_arguments,
520+
allow_errors=env.config.nbsphinx_allow_errors,
521+
timeout=env.config.nbsphinx_timeout,
522+
codecell_lexer=env.config.nbsphinx_codecell_lexer,
523+
)
519524

520525
try:
521526
rststring, resources = exporter.from_notebook_node(nb, resources)
@@ -1137,6 +1142,7 @@ def setup(app):
11371142
_add_notebook_parser(app)
11381143

11391144
app.add_config_value('nbsphinx_execute', 'auto', rebuild='env')
1145+
app.add_config_value('nbsphinx_execute_arguments', [], rebuild='env')
11401146
app.add_config_value('nbsphinx_allow_errors', False, rebuild='')
11411147
app.add_config_value('nbsphinx_timeout', 30, rebuild='')
11421148
app.add_config_value('nbsphinx_codecell_lexer', 'none', rebuild='env')

0 commit comments

Comments
 (0)