diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index 2308ba664..fe80c5d66 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -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 @@ -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 diff --git a/nbconvert/preprocessors/tests/test_execute.py b/nbconvert/preprocessors/tests/test_execute.py index f6657fff9..52af82508 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/nbconvert/preprocessors/tests/test_execute.py @@ -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')