From 6a767073d6a010ca14eaa5c43e4567e0b5bf2f57 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Thu, 12 Sep 2024 17:25:23 +0200 Subject: [PATCH] Bump ypywidgets, fix display_output handling --- .../kernels/fps_kernels/kernel_driver/driver.py | 16 ++++++++-------- plugins/yjs/fps_yjs/ywidgets/widgets.py | 16 ++++++++-------- pyproject.toml | 4 ++-- tests/test_server.py | 8 ++++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/plugins/kernels/fps_kernels/kernel_driver/driver.py b/plugins/kernels/fps_kernels/kernel_driver/driver.py index d1761b77..9cfad609 100644 --- a/plugins/kernels/fps_kernels/kernel_driver/driver.py +++ b/plugins/kernels/fps_kernels/kernel_driver/driver.py @@ -257,14 +257,14 @@ async def _handle_outputs(self, outputs: Array, msg: Dict[str, Any]): await self.yjs.room_manager.websocket_server.get_room(path, ydoc=doc) # type: ignore outputs.append(doc) else: - outputs.append( - { - "data": {"text/plain": [content["data"].get("text/plain", "")]}, - "execution_count": content["execution_count"], - "metadata": {}, - "output_type": msg_type, - } - ) + output = { + "data": content["data"], + "metadata": {}, + "output_type": msg_type, + } + if msg_type == "execute_result": + output["execution_count"] = content["execution_count"] + outputs.append(output) elif msg_type == "error": outputs.append( { diff --git a/plugins/yjs/fps_yjs/ywidgets/widgets.py b/plugins/yjs/fps_yjs/ywidgets/widgets.py index 52eeae03..d5d7f4c2 100644 --- a/plugins/yjs/fps_yjs/ywidgets/widgets.py +++ b/plugins/yjs/fps_yjs/ywidgets/widgets.py @@ -1,15 +1,15 @@ import sys from typing import Any -from pycrdt import TransactionEvent - try: - from ypywidgets.utils import ( # type: ignore + import ypywidgets # noqa: F401 + from pycrdt import ( + TransactionEvent, YMessageType, YSyncMessageType, + create_sync_message, create_update_message, - process_sync_message, - sync, + handle_sync_message, ) ypywidgets_installed = True except ImportError: @@ -41,15 +41,15 @@ def comm_open(self, msg, comm) -> None: self.comm = comm model = self.ydocs[f"{name}Model"]() self.widgets[comm_id] = {"model": model, "comm": comm} - msg = sync(model.ydoc) - comm.send(**msg) + msg = create_sync_message(model.ydoc) + comm.send(buffers=[msg]) def comm_msg(self, msg) -> None: comm_id = msg["content"]["comm_id"] message = bytes(msg["buffers"][0]) if message[0] == YMessageType.SYNC: ydoc = self.widgets[comm_id]["model"].ydoc - reply = process_sync_message( + reply = handle_sync_message( message[1:], ydoc, ) diff --git a/pyproject.toml b/pyproject.toml index d5f8e585..297a424d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,8 +54,8 @@ test = [ "requests", "websockets", "ipykernel", - "ypywidgets >=0.7.0,<0.8.0", - "ypywidgets-textual >=0.4.0,<0.5.0", + "ypywidgets >=0.9.3,<0.10.0", + "ypywidgets-textual >=0.5.0,<0.6.0", ] docs = [ "mkdocs", "mkdocs-material" ] diff --git a/tests/test_server.py b/tests/test_server.py index 0ba0cc03..66a986d4 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -106,8 +106,8 @@ async def test_rest_api(start_jupyverse): cells = json.loads(str(ycells)) assert cells[0]["outputs"] == [ { - "data": {"text/plain": ["3"]}, - "execution_count": 1.0, + "data": {"text/plain": "3"}, + "execution_count": 1, "metadata": {}, "output_type": "execute_result", } @@ -117,8 +117,8 @@ async def test_rest_api(start_jupyverse): ] assert cells[2]["outputs"] == [ { - "data": {"text/plain": ["7"]}, - "execution_count": 3.0, + "data": {"text/plain": "7"}, + "execution_count": 3, "metadata": {}, "output_type": "execute_result", }