Skip to content

Commit c832b07

Browse files
committed
-
1 parent 17b11f7 commit c832b07

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
pip install ./plugins/yjs
4646
pip install ./plugins/lab
4747
pip install ./plugins/jupyterlab
48+
pip install "jupyter-ydoc>=0.1.16,<0.2.0"
4849
4950
pip install mypy pytest pytest-asyncio requests ipykernel
5051

plugins/kernels/fps_kernels/routes.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,19 @@ async def restart_kernel(
175175

176176
@router.post("/api/kernels/{kernel_id}/execute")
177177
async def execute_cell(
178-
execution: Execution,
178+
request: Request,
179179
kernel_id,
180180
user: UserRead = Depends(current_user),
181181
):
182+
r = await request.json()
183+
execution = Execution(**r)
184+
with open("log.txt", "a") as f:
185+
f.write(str(execution.cell_idx) + "\n")
182186
if kernel_id in kernels:
183-
room = YDocWebSocketHandler.websocket_server.get_room(execution.document_id)
184-
nb = room.document.source
185-
cell = nb["cells"][execution.cell_idx]
187+
ynotebook = YDocWebSocketHandler.websocket_server.get_room(execution.document_id).document
188+
cell = ynotebook.get_cell(execution.cell_idx)
189+
with open("log.txt", "a") as f:
190+
f.write(str(cell) + "\n")
186191
cell["outputs"] = []
187192

188193
kernel = kernels[kernel_id]
@@ -199,7 +204,9 @@ async def execute_cell(
199204
driver = kernel["driver"]
200205

201206
await driver.execute(cell)
202-
room.document.source = nb
207+
with open("log.txt", "a") as f:
208+
f.write(str(cell) + "\n")
209+
ynotebook.set_cell(execution.cell_idx, cell)
203210

204211

205212
@router.get("/api/kernels/{kernel_id}")

plugins/yjs/setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ install_requires =
2323
fps >=0.0.8
2424
fps-auth
2525
fps-contents
26-
jupyter_ydoc >=0.1.10
27-
ypy-websocket >=0.1.13
26+
jupyter_ydoc >=0.1.16,<0.2.0
27+
ypy-websocket >=0.3.1,<0.4.0
2828

2929
[options.entry_points]
3030
fps_router =

tests/conftest.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_open_port():
7373

7474

7575
@pytest.fixture()
76-
def start_jupyverse(auth_mode, clear_users, cwd, capfd):
76+
def start_jupyverse(auth_mode, clear_users, cwd):#, capfd):
7777
os.chdir(cwd)
7878
port = get_open_port()
7979
command_list = [
@@ -86,14 +86,15 @@ def start_jupyverse(auth_mode, clear_users, cwd, capfd):
8686
print(" ".join(command_list))
8787
p = subprocess.Popen(command_list)
8888
dtime, ttime, timeout = 0.1, 0, 10
89-
while True:
90-
time.sleep(dtime)
91-
ttime += dtime
92-
if ttime >= timeout:
93-
raise RuntimeError("Timeout while launching Jupyverse")
94-
out, err = capfd.readouterr()
95-
if "Application startup complete" in err:
96-
break
89+
time.sleep(2)
90+
#while True:
91+
# time.sleep(dtime)
92+
# ttime += dtime
93+
# if ttime >= timeout:
94+
# raise RuntimeError("Timeout while launching Jupyverse")
95+
# out, err = capfd.readouterr()
96+
# if "Application startup complete" in err:
97+
# break
9798
url = f"http://127.0.0.1:{port}"
9899
yield url
99100
p.kill()

tests/data/notebook0.ipynb

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
{
44
"source": "1 + 2",
55
"outputs": [],
6-
"metadata": {
7-
"trusted": 0
8-
},
96
"cell_type": "code",
107
"execution_count": null,
118
"id": "a7243792-6f06-4462-a6b5-7e9ec604348e"
@@ -15,17 +12,11 @@
1512
"source": "print(\"Hello World!\")",
1613
"outputs": [],
1714
"cell_type": "code",
18-
"execution_count": null,
19-
"metadata": {
20-
"trusted": 0
21-
}
15+
"execution_count": null
2216
},
2317
{
2418
"source": "3 + 4",
2519
"outputs": [],
26-
"metadata": {
27-
"trusted": 0
28-
},
2920
"cell_type": "code",
3021
"execution_count": null,
3122
"id": "a7243792-6f06-4462-a6b5-7e9ec604348f"

tests/test_server.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import pytest
55
import requests
66
from websockets import connect
7-
from ypy_websocket import WebsocketProvider, YDoc
7+
from ypy_websocket import WebsocketProvider
8+
import y_py as Y
89

910
prev_theme = {}
1011
test_theme = {"raw": '{// jupyverse test\n"theme": "JupyterLab Dark"}'}
@@ -66,7 +67,7 @@ async def test_rest_api(start_jupyverse):
6667
document_id = "json:notebook:tests/data/notebook0.ipynb"
6768
async with connect(f"{ws_url}/api/yjs/{document_id}") as websocket:
6869
# connect to the shared notebook document
69-
ydoc = YDoc()
70+
ydoc = Y.YDoc()
7071
WebsocketProvider(ydoc, websocket)
7172
# wait for file to be loaded and Y model to be created in server and client
7273
await asyncio.sleep(0.1)
@@ -85,6 +86,7 @@ async def test_rest_api(start_jupyverse):
8586
await asyncio.sleep(0.1)
8687
# retrieve cells
8788
cells = ydoc.get_array("cells").to_json()
89+
print("cells =", cells)
8890
assert cells[0]["outputs"] == [
8991
{
9092
"data": {"text/plain": ["3"]},

0 commit comments

Comments
 (0)