Skip to content

Commit

Permalink
jupyter#751 adding widget metadata moved to separate method
Browse files Browse the repository at this point in the history
ipywidgets min version changed to 7
  • Loading branch information
Lukasz Mitusinski committed Mar 22, 2018
1 parent a7d8cc3 commit 9d57289
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions nbconvert/preprocessors/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,29 @@ def start_new_kernel(startup_timeout=60, kernel_name='python', **kwargs):
finally:
self.kc.stop_channels()
self.km.shutdown_kernel(now=self.shutdown_kernel == 'immediate')
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
self.set_widgets_metadata()

delattr(self, 'nb')

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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def run(self):
]

extra_requirements = {
'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2', 'ipywidgets'],
'test': ['pytest', 'pytest-cov', 'ipykernel', 'jupyter_client>=4.2', 'ipywidgets>=7'],
'serve': ['tornado>=4.0'],
'execute': ['jupyter_client>=4.2'],
}
Expand Down

0 comments on commit 9d57289

Please sign in to comment.