Skip to content

Commit

Permalink
Merge pull request #860 from akhmerov/feature/execute-language-metadata
Browse files Browse the repository at this point in the history
populate language_info metadata when executing
  • Loading branch information
mpacer authored Aug 23, 2018
2 parents c60f7ad + 5847efd commit 1a7b848
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nbconvert/preprocessors/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ def preprocess(self, nb, resources, km=None):
with self.setup_preprocessor(nb, resources, km=km):
self.log.info("Executing notebook with kernel: %s" % self.kernel_name)
nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)
info_msg = self._wait_for_reply(self.kc.kernel_info())
nb.metadata['language_info'] = info_msg['content']['language_info']

return nb, resources

Expand Down Expand Up @@ -407,11 +409,11 @@ def _update_display_id(self, display_id, msg):
outputs[output_idx]['data'] = out['data']
outputs[output_idx]['metadata'] = out['metadata']

def _wait_for_reply(self, msg_id, cell):
def _wait_for_reply(self, msg_id, cell=None):
# wait for finish, with timeout
while True:
try:
if self.timeout_func is not None:
if self.timeout_func is not None and cell is not None:
timeout = self.timeout_func(cell)
else:
timeout = self.timeout
Expand Down
6 changes: 6 additions & 0 deletions nbconvert/preprocessors/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def test_run_notebooks(self):
input_nb, output_nb = self.run_notebook(filename, opts, res)
self.assert_notebooks_equal(input_nb, output_nb)

def test_populate_language_info(self):
preprocessor = self.build_preprocessor(opts=dict(kernel_name="python"))
nb = nbformat.v4.new_notebook() # Certainly has no language_info.
nb, _ = preprocessor.preprocess(nb, resources={})
assert 'language_info' in nb.metadata

def test_empty_path(self):
"""Can the kernel be started when the path is empty?"""
filename = os.path.join(current_dir, 'files', 'HelloWorld.ipynb')
Expand Down

0 comments on commit 1a7b848

Please sign in to comment.