Skip to content

Commit

Permalink
Import sync from pycrdt
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 13, 2024
1 parent 35984d0 commit 4656e0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
16 changes: 8 additions & 8 deletions plugins/yjs/fps_yjs/ywidgets/widgets.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import sys
from typing import Any

from pycrdt import TransactionEvent

try:
from ypywidgets.utils import ( # type: ignore
import ypywidgets # type: ignore # 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:
Expand Down Expand Up @@ -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,
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async def recv(self) -> bytes:
return bytes(b)


@pytest.mark.skip(reason="FIXME: caused by new ypywidgets version")
@pytest.mark.asyncio
@pytest.mark.parametrize("auth_mode", ("noauth",))
async def test_execute(auth_mode, unused_tcp_port):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand All @@ -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",
}
Expand Down

0 comments on commit 4656e0d

Please sign in to comment.