Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jul 27, 2022
1 parent 17b11f7 commit c832b07
Showing 6 changed files with 30 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ jobs:
pip install ./plugins/yjs
pip install ./plugins/lab
pip install ./plugins/jupyterlab
pip install "jupyter-ydoc>=0.1.16,<0.2.0"
pip install mypy pytest pytest-asyncio requests ipykernel
17 changes: 12 additions & 5 deletions plugins/kernels/fps_kernels/routes.py
Original file line number Diff line number Diff line change
@@ -175,14 +175,19 @@ async def restart_kernel(

@router.post("/api/kernels/{kernel_id}/execute")
async def execute_cell(
execution: Execution,
request: Request,
kernel_id,
user: UserRead = Depends(current_user),
):
r = await request.json()
execution = Execution(**r)
with open("log.txt", "a") as f:
f.write(str(execution.cell_idx) + "\n")
if kernel_id in kernels:
room = YDocWebSocketHandler.websocket_server.get_room(execution.document_id)
nb = room.document.source
cell = nb["cells"][execution.cell_idx]
ynotebook = YDocWebSocketHandler.websocket_server.get_room(execution.document_id).document
cell = ynotebook.get_cell(execution.cell_idx)
with open("log.txt", "a") as f:
f.write(str(cell) + "\n")
cell["outputs"] = []

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

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


@router.get("/api/kernels/{kernel_id}")
4 changes: 2 additions & 2 deletions plugins/yjs/setup.cfg
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ install_requires =
fps >=0.0.8
fps-auth
fps-contents
jupyter_ydoc >=0.1.10
ypy-websocket >=0.1.13
jupyter_ydoc >=0.1.16,<0.2.0
ypy-websocket >=0.3.1,<0.4.0

[options.entry_points]
fps_router =
19 changes: 10 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ def get_open_port():


@pytest.fixture()
def start_jupyverse(auth_mode, clear_users, cwd, capfd):
def start_jupyverse(auth_mode, clear_users, cwd):#, capfd):
os.chdir(cwd)
port = get_open_port()
command_list = [
@@ -86,14 +86,15 @@ def start_jupyverse(auth_mode, clear_users, cwd, capfd):
print(" ".join(command_list))
p = subprocess.Popen(command_list)
dtime, ttime, timeout = 0.1, 0, 10
while True:
time.sleep(dtime)
ttime += dtime
if ttime >= timeout:
raise RuntimeError("Timeout while launching Jupyverse")
out, err = capfd.readouterr()
if "Application startup complete" in err:
break
time.sleep(2)
#while True:
# time.sleep(dtime)
# ttime += dtime
# if ttime >= timeout:
# raise RuntimeError("Timeout while launching Jupyverse")
# out, err = capfd.readouterr()
# if "Application startup complete" in err:
# break
url = f"http://127.0.0.1:{port}"
yield url
p.kill()
11 changes: 1 addition & 10 deletions tests/data/notebook0.ipynb
Original file line number Diff line number Diff line change
@@ -3,9 +3,6 @@
{
"source": "1 + 2",
"outputs": [],
"metadata": {
"trusted": 0
},
"cell_type": "code",
"execution_count": null,
"id": "a7243792-6f06-4462-a6b5-7e9ec604348e"
@@ -15,17 +12,11 @@
"source": "print(\"Hello World!\")",
"outputs": [],
"cell_type": "code",
"execution_count": null,
"metadata": {
"trusted": 0
}
"execution_count": null
},
{
"source": "3 + 4",
"outputs": [],
"metadata": {
"trusted": 0
},
"cell_type": "code",
"execution_count": null,
"id": "a7243792-6f06-4462-a6b5-7e9ec604348f"
6 changes: 4 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
import pytest
import requests
from websockets import connect
from ypy_websocket import WebsocketProvider, YDoc
from ypy_websocket import WebsocketProvider
import y_py as Y

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

0 comments on commit c832b07

Please sign in to comment.