Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcarlos committed Oct 5, 2023
1 parent b8d5036 commit afc6df5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
4 changes: 1 addition & 3 deletions jupyter_collaboration/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from __future__ import annotations

import asyncio
from anyio import create_task_group
from anyio.abc import TaskGroup

from jupyter_server.extension.application import ExtensionApp
from traitlets import Bool, Float, Type
Expand Down Expand Up @@ -83,7 +81,7 @@ def initialize_handlers(self):
# Set configurable parameters to YStore class
for k, v in self.config.get(self.ystore_class.__name__, {}).items():
setattr(self.ystore_class, k, v)

# Instantiate the store
self._store = self.ystore_class(log=self.log)

Expand Down
4 changes: 2 additions & 2 deletions jupyter_collaboration/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from jupyter_ydoc import ydocs as YDOCS
from tornado import web
from tornado.websocket import WebSocketHandler
from ypy_websocket.websocket_server import YRoom
from ypy_websocket.stores import BaseYStore
from ypy_websocket.websocket_server import YRoom
from ypy_websocket.yutils import YMessageType, write_var_uint

from .loaders import FileLoaderMapping
Expand Down Expand Up @@ -62,7 +62,7 @@ def create_task(self, aw):
task.add_done_callback(self._background_tasks.discard)

async def prepare(self):
# NOTE: Initialize in the ExtensionApp.start_extension once
# NOTE: Initialize in the ExtensionApp.start_extension once
# https://github.com/jupyter-server/jupyter_server/issues/1329
# is done.
# We are temporarily initializing the store here because `start``
Expand Down
33 changes: 25 additions & 8 deletions jupyter_collaboration/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from jupyter_events import EventLogger
from jupyter_ydoc import ydocs as YDOCS
from ypy_websocket.stores import BaseYStore
from ypy_websocket.websocket_server import YRoom
from ypy_websocket.stores import BaseYStore, YDocNotFound
from ypy_websocket.yutils import write_var_uint

from .loaders import FileLoader
Expand Down Expand Up @@ -111,14 +111,30 @@ async def initialize(self) -> None:
if self.ystore is not None and await self.ystore.exists(self._room_id):
# Load the content from the store
await self.ystore.apply_updates(self._room_id, self.ydoc)
self._emit(LogLevel.INFO, "load", "Content loaded from the store {}".format(self.ystore.__class__.__qualname__))
self.log.info("Content in room %s loaded from the ystore %s", self._room_id, self.ystore.__class__.__name__,)
self._emit(
LogLevel.INFO,
"load",
"Content loaded from the store {}".format(
self.ystore.__class__.__qualname__
),
)
self.log.info(
"Content in room %s loaded from the ystore %s",
self._room_id,
self.ystore.__class__.__name__,
)

# if YStore updates and source file are out-of-sync, resync updates with source
if self._document.source != model["content"]:
self._emit(LogLevel.INFO, "initialize", "The file is out-of-sync with the ystore.")
self.log.info("Content in file %s is out-of-sync with the ystore %s", self._file.path, self.ystore.__class__.__name__,)

self._emit(
LogLevel.INFO, "initialize", "The file is out-of-sync with the ystore."
)
self.log.info(
"Content in file %s is out-of-sync with the ystore %s",
self._file.path,
self.ystore.__class__.__name__,
)

doc = await self.ystore.get(self._room_id)
await self.ystore.remove(self._room_id)
version = 0
Expand All @@ -130,14 +146,15 @@ async def initialize(self) -> None:

else:
self._emit(LogLevel.INFO, "load", "Content loaded from disk.")
self.log.info("Content in room %s loaded from file %s", self._room_id, self._file.path)
self.log.info(
"Content in room %s loaded from file %s", self._room_id, self._file.path
)
self._document.source = model["content"]

if self.ystore is not None:
await self.ystore.create(self._room_id, 0)
await self.ystore.encode_state_as_update(self._room_id, self.ydoc)


self._last_modified = model["last_modified"]
self._document.dirty = False
self.ready = True
Expand Down
4 changes: 2 additions & 2 deletions jupyter_collaboration/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from __future__ import annotations

from logging import Logger

from traitlets import Int, Unicode
from traitlets.config import LoggingConfigurable

from ypy_websocket.stores import SQLiteYStore as _SQLiteYStore
from ypy_websocket.stores import FileYStore
from ypy_websocket.stores import SQLiteYStore as _SQLiteYStore


class TempFileYStore(FileYStore):
Expand Down
1 change: 0 additions & 1 deletion jupyter_collaboration/websocketserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from tornado.websocket import WebSocketHandler
from ypy_websocket.websocket_server import WebsocketServer, YRoom
from ypy_websocket.stores import BaseYStore


class RoomNotFound(LookupError):
Expand Down
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,20 @@ def rtc_create_SQLite_store(jp_serverapp):
setattr(SQLiteYStore, k, v)

async def _inner(type: str, path: str, content: str) -> DocumentRoom:
db = SQLiteYStore(path=f"{type}:{path}")
room_id = f"{type}:{path}"
db = SQLiteYStore()
await db.start()
await db.initialize()

if type == "notebook":
doc = YNotebook()
else:
doc = YUnicode()

doc.source = content
await db.encode_state_as_update(doc.ydoc)

await db.create(room_id, 0)
await db.encode_state_as_update(room_id, doc.ydoc)

return db

Expand Down

0 comments on commit afc6df5

Please sign in to comment.