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 13, 2021
1 parent b6f6dbc commit 16d0f57
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions ipywidgets/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4]))

__protocol_version__ = '2.0.0'
__control_protocol_version__ = '1.0.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
12 changes: 7 additions & 5 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

from base64 import standard_b64encode

from .._version import __protocol_version__, __jupyter_widgets_base_version__
from .._version import __protocol_version__, __control_protocol_version__, __jupyter_widgets_base_version__
PROTOCOL_VERSION_MAJOR = __protocol_version__.split('.')[0]
CONTROL_PROTOCOL_VERSION_MAJOR = __control_protocol_version__.split('.')[0]

def _widget_to_json(x, obj):
if isinstance(x, dict):
Expand Down Expand Up @@ -319,6 +320,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] != CONTROL_PROTOCOL_VERSION_MAJOR:
raise ValueError("Incompatible widget control protocol versions: received version %r, expected version %r"%(version, __control_protocol_version__))

cls.get_manager_state()
widgets = Widget.widgets.values()
# build a single dict with the full widget state
Expand All @@ -332,10 +337,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
1 change: 0 additions & 1 deletion packages/base/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ const JUPYTER_WIDGETS_VERSION = '1.2.0';

export
const PROTOCOL_VERSION = '2.0.0';

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




# Control Widget messaging protocol, version 1.0

This is implemented in ipywidgets 7.7.

### 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 16d0f57

Please sign in to comment.