From 174763410489191ec73f70417ca9e0ec1033368c Mon Sep 17 00:00:00 2001 From: Lukasz Mitusinski Date: Thu, 22 Mar 2018 11:52:38 +0100 Subject: [PATCH] #751 adding widget metadata moved to separate method ipywidgets min version changed to 7 --- nbconvert/preprocessors/execute.py | 17 +++++++++++++++++ setup.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index a1b379826..6e741532f 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -358,6 +358,23 @@ def preprocess(self, nb, resources, km=None): return nb, resources + def set_widgets_metadata(self): + if self.widget_state: + self.nb.metadata.widgets = { + 'application/vnd.jupyter.widget-state+json': { + 'state': { + model_id: _serialize_widget_state(state) + for model_id, state in self.widget_state.items() if '_model_name' in state + }, + 'version_major': 2, + 'version_minor': 0, + } + } + for key, widget in self.nb.metadata.widgets['application/vnd.jupyter.widget-state+json']['state'].items(): + buffers = self.widget_buffers.get(key) + if buffers: + widget['buffers'] = buffers + def preprocess_cell(self, cell, resources, cell_index): """ Executes a single code cell. See base.py for details. diff --git a/setup.py b/setup.py index eed6a741f..56682b6a9 100644 --- a/setup.py +++ b/setup.py @@ -213,7 +213,7 @@ def run(self): jupyter_client_req = 'jupyter_client>=4.2' extra_requirements = { -(??) 'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2'], + 'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2', 'ipywidgets>=7'], 'serve': ['tornado>=4.0'], 'execute': [jupyter_client_req], 'docs': ['sphinx>=1.5.1',