Skip to content

Commit

Permalink
Remove asyncio leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Feb 13, 2025
1 parent aacde8a commit 1f3aa09
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 26 deletions.
1 change: 0 additions & 1 deletion .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
fps[unicorn] >=0.0.10
mypy
pytest
pytest-asyncio
2 changes: 1 addition & 1 deletion plugins/jupyterlab/fps_jupyterlab/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def get_workspace(
)

def get_index(self, workspace, collaborative, server_side_execution, dev_mode, base_url="/"):
for path in (self.static_lab_dir).glob("main.*.js"):
for path in self.static_lab_dir.glob("main.*.js"):
main_id = path.name.split(".")[1]
break
vendor_id = None
Expand Down
15 changes: 15 additions & 0 deletions plugins/webdav/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from socket import socket

import pytest


@pytest.fixture
def anyio_backend():
return "asyncio"


@pytest.fixture()
def unused_tcp_port() -> int:
with socket() as sock:
sock.bind(("127.0.0.1", 0))
return sock.getsockname()[1]
6 changes: 0 additions & 6 deletions plugins/webdav/tests/conftext.py

This file was deleted.

1 change: 0 additions & 1 deletion plugins/webdav/tests/test_webdav.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@


@pytest.mark.anyio
@pytest.mark.parametrize("anyio_backend", ["asyncio"])
@pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python >=3.10")
async def test_webdav(unused_tcp_port):
config = merge_config(
Expand Down
14 changes: 9 additions & 5 deletions plugins/yjs/fps_yjs/routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

import logging
from datetime import datetime
from functools import partial
from typing import Dict
from uuid import uuid4

import structlog
from anyio import TASK_STATUS_IGNORED, create_task_group, sleep
from anyio.abc import TaskStatus
from anyioutils import Task, create_task
Expand Down Expand Up @@ -36,7 +36,7 @@
YFILE = YDOCS["file"]
AWARENESS = 1
SERVER_SESSION = uuid4().hex
logger = logging.getLogger("yjs")
logger = structlog.get_logger()


class JupyterSQLiteYStore(SQLiteYStore):
Expand Down Expand Up @@ -205,7 +205,11 @@ async def serve(self, websocket: YWebsocket, permissions) -> None:
del self.cleaners[room]
if not room.ready:
file_path = await self.contents.file_id_manager.get_path(file_id)
logger.info(f"Opening collaboration room: {websocket.path} ({file_path})")
logger.info(
"Opening collaboration room",
room_id=websocket.path,
file_path=file_path,
)
document = YDOCS.get(file_type, YFILE)(room.ydoc)
document.file_id = file_id
self.documents[websocket.path] = document
Expand Down Expand Up @@ -292,7 +296,7 @@ async def get_file_path(self, file_id: str, document) -> str | None:
async def watch_file(self, file_format: str, file_id: str, document: YBaseDoc) -> None:
file_path = await self.get_file_path(file_id, document)
assert file_path is not None
logger.debug(f"Watching file: {file_path}")
logger.info("Watching file", path=file_path)
# FIXME: handle file rename/move?
watcher = self.contents.file_id_manager.watch(file_path)
async for changes in watcher:
Expand Down Expand Up @@ -395,7 +399,7 @@ async def maybe_clean_room(self, room, ws_path: str) -> None:
room_name = self.websocket_server.get_room_name(room)
self.websocket_server.delete_room(room=room)
file_path = await self.get_file_path(file_id, document)
logger.info(f"Closing collaboration room: {room_name} ({file_path})")
logger.info("Closing collaboration room", room_id=room_name, file_path=file_path)
if room in self.cleaners:
del self.cleaners[room]

Expand Down
16 changes: 8 additions & 8 deletions plugins/yjs/fps_yjs/ywebsocket/django_channels_consumer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

from logging import getLogger
from typing import TypedDict

from channels.generic.websocket import AsyncWebsocketConsumer # type: ignore
from pycrdt import Doc, YMessageType, YSyncMessageType, create_sync_message, handle_sync_message
from structlog import get_logger

from .websocket import Websocket

logger = getLogger(__name__)
logger = get_logger()


class _WebsocketShim(Websocket):
Expand Down Expand Up @@ -160,9 +160,9 @@ async def connect(self) -> None:

sync_message = create_sync_message(self.ydoc)
logger.debug(
"Sending %s message to endpoint: %s",
YSyncMessageType.SYNC_STEP1.name,
self._websocket_shim.path,
"Sending message",
name=YSyncMessageType.SYNC_STEP1.name,
endpoint=self._websocket_shim.path,
)
await self._websocket_shim.send(sync_message)

Expand All @@ -178,9 +178,9 @@ async def receive(self, text_data=None, bytes_data=None):
reply = handle_sync_message(bytes_data[1:], self.ydoc)
if reply is not None:
logger.debug(
"Sending %s message to endpoint: %s",
YSyncMessageType.SYNC_STEP2.name,
self._websocket_shim.path,
"Sending message",
name=YSyncMessageType.SYNC_STEP2.name,
endpoint=self._websocket_shim.path,
)
await self._websocket_shim.send(reply)

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ test = [
"mypy",
"types-setuptools",
"pytest",
"pytest-asyncio",
"pytest-rerunfailures",
"pytest-timeout",
"pytest-env",
Expand Down
11 changes: 10 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import subprocess
import time
from pathlib import Path
from socket import socket

import pytest
import requests


@pytest.fixture
def anyio_backend():
# at least, SQLAlchemy doesn't support anything else than asyncio
# at least, SQLAlchemy and pyzmq don't support anything else than asyncio
# TODO: switch to zmq-anyio
return "asyncio"


Expand All @@ -19,6 +21,13 @@ def cwd():
return Path(__file__).parents[1]


@pytest.fixture()
def unused_tcp_port() -> int:
with socket() as sock:
sock.bind(("127.0.0.1", 0))
return sock.getsockname()[1]


@pytest.fixture()
def start_jupyverse(auth_mode, clear_users, cwd, unused_tcp_port):
os.chdir(cwd)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def test_root_auth(auth_mode, unused_tcp_port):
assert response.headers["content-type"] == "application/json"


@pytest.mark.asyncio
@pytest.mark.anyio
@pytest.mark.parametrize("auth_mode", ("noauth",))
async def test_no_auth(auth_mode, unused_tcp_port):
config = merge_config(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}


@pytest.mark.asyncio
@pytest.mark.anyio
@pytest.mark.parametrize("auth_mode", ("noauth",))
async def test_tree(auth_mode, tmp_path, unused_tcp_port):
prev_dir = os.getcwd()
Expand Down

0 comments on commit 1f3aa09

Please sign in to comment.