Skip to content

Commit

Permalink
Docs + remove buffer hack
Browse files Browse the repository at this point in the history
I removed the buffer hack. This shouldn't be required anymore since the
removal of json_clean in ipykernel. We should also see if we can improve
performances in jupyter-server.
  • Loading branch information
martinRenou committed Oct 11, 2021
1 parent b6f6dbc commit d2c9083
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ipywidgets/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__version__ = '%s.%s.%s%s'%(version_info[0], version_info[1], version_info[2],
'' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4]))

__protocol_version__ = '2.0.0'
__protocol_version__ = '2.1.0'

# These are *protocol* versions for each package, *not* npm versions. To check, look at each package's src/version.ts file for the protocol version the package implements.
__jupyter_widgets_base_version__ = '1.2.0'
Expand Down
9 changes: 5 additions & 4 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ def _call_widget_constructed(widget):

@classmethod
def handle_comm_opened_control(cls, comm, msg):
version = msg.get('metadata', {}).get('version', '')
if version.split('.')[0] != PROTOCOL_VERSION_MAJOR:
raise ValueError("Incompatible widget protocol versions: received version %r, expected version %r"%(version, __protocol_version__))

cls.get_manager_state()
widgets = Widget.widgets.values()
# build a single dict with the full widget state
Expand All @@ -332,10 +336,7 @@ def handle_comm_opened_control(cls, comm, msg):
'state': widget.get_state(drop_defaults=drop_defaults),
}
full_state, buffer_paths, buffers = _remove_buffers(full_state)
# the message is also send as buffer, so it does not get handled by jupyter_server
msg = jsondumps([full_state, buffer_paths]).encode('utf8')
buffers.insert(0, msg)
comm.send(buffers=buffers)
comm.send([full_state, buffer_paths], buffers=buffers)

@staticmethod
def handle_comm_opened(comm, msg):
Expand Down
3 changes: 1 addition & 2 deletions packages/base/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export
const JUPYTER_WIDGETS_VERSION = '1.2.0';

export
const PROTOCOL_VERSION = '2.0.0';

const PROTOCOL_VERSION = '2.1.0';
13 changes: 13 additions & 0 deletions packages/schema/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,16 @@ To display a widget, the kernel sends a Jupyter [iopub `display_data` message](h
}
}
```




# Widget messaging protocol, version 2.1

This is implemented in ipywidgets 7.7.

## Changes from version 2

### The `jupyter.widget.control` comm target

A kernel-side Jupyter widgets library registers a `jupyter.widget.control` comm target that is used for fetching all widgets states through a "one shot" comm message (one for all widget instances). The kernel-side widgets library must answer to the "comm-open" message with a comm message containing the full state of all widget instances.

0 comments on commit d2c9083

Please sign in to comment.