Skip to content

Commit afc6df5

Browse files
committed
pre-commit
1 parent b8d5036 commit afc6df5

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

jupyter_collaboration/app.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from __future__ import annotations
44

55
import asyncio
6-
from anyio import create_task_group
7-
from anyio.abc import TaskGroup
86

97
from jupyter_server.extension.application import ExtensionApp
108
from traitlets import Bool, Float, Type
@@ -83,7 +81,7 @@ def initialize_handlers(self):
8381
# Set configurable parameters to YStore class
8482
for k, v in self.config.get(self.ystore_class.__name__, {}).items():
8583
setattr(self.ystore_class, k, v)
86-
84+
8785
# Instantiate the store
8886
self._store = self.ystore_class(log=self.log)
8987

jupyter_collaboration/handlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from jupyter_ydoc import ydocs as YDOCS
1515
from tornado import web
1616
from tornado.websocket import WebSocketHandler
17-
from ypy_websocket.websocket_server import YRoom
1817
from ypy_websocket.stores import BaseYStore
18+
from ypy_websocket.websocket_server import YRoom
1919
from ypy_websocket.yutils import YMessageType, write_var_uint
2020

2121
from .loaders import FileLoaderMapping
@@ -62,7 +62,7 @@ def create_task(self, aw):
6262
task.add_done_callback(self._background_tasks.discard)
6363

6464
async def prepare(self):
65-
# NOTE: Initialize in the ExtensionApp.start_extension once
65+
# NOTE: Initialize in the ExtensionApp.start_extension once
6666
# https://github.com/jupyter-server/jupyter_server/issues/1329
6767
# is done.
6868
# We are temporarily initializing the store here because `start``

jupyter_collaboration/rooms.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from jupyter_events import EventLogger
1212
from jupyter_ydoc import ydocs as YDOCS
13+
from ypy_websocket.stores import BaseYStore
1314
from ypy_websocket.websocket_server import YRoom
14-
from ypy_websocket.stores import BaseYStore, YDocNotFound
1515
from ypy_websocket.yutils import write_var_uint
1616

1717
from .loaders import FileLoader
@@ -111,14 +111,30 @@ async def initialize(self) -> None:
111111
if self.ystore is not None and await self.ystore.exists(self._room_id):
112112
# Load the content from the store
113113
await self.ystore.apply_updates(self._room_id, self.ydoc)
114-
self._emit(LogLevel.INFO, "load", "Content loaded from the store {}".format(self.ystore.__class__.__qualname__))
115-
self.log.info("Content in room %s loaded from the ystore %s", self._room_id, self.ystore.__class__.__name__,)
114+
self._emit(
115+
LogLevel.INFO,
116+
"load",
117+
"Content loaded from the store {}".format(
118+
self.ystore.__class__.__qualname__
119+
),
120+
)
121+
self.log.info(
122+
"Content in room %s loaded from the ystore %s",
123+
self._room_id,
124+
self.ystore.__class__.__name__,
125+
)
116126

117127
# if YStore updates and source file are out-of-sync, resync updates with source
118128
if self._document.source != model["content"]:
119-
self._emit(LogLevel.INFO, "initialize", "The file is out-of-sync with the ystore.")
120-
self.log.info("Content in file %s is out-of-sync with the ystore %s", self._file.path, self.ystore.__class__.__name__,)
121-
129+
self._emit(
130+
LogLevel.INFO, "initialize", "The file is out-of-sync with the ystore."
131+
)
132+
self.log.info(
133+
"Content in file %s is out-of-sync with the ystore %s",
134+
self._file.path,
135+
self.ystore.__class__.__name__,
136+
)
137+
122138
doc = await self.ystore.get(self._room_id)
123139
await self.ystore.remove(self._room_id)
124140
version = 0
@@ -130,14 +146,15 @@ async def initialize(self) -> None:
130146

131147
else:
132148
self._emit(LogLevel.INFO, "load", "Content loaded from disk.")
133-
self.log.info("Content in room %s loaded from file %s", self._room_id, self._file.path)
149+
self.log.info(
150+
"Content in room %s loaded from file %s", self._room_id, self._file.path
151+
)
134152
self._document.source = model["content"]
135153

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

140-
141158
self._last_modified = model["last_modified"]
142159
self._document.dirty = False
143160
self.ready = True

jupyter_collaboration/stores.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from __future__ import annotations
55

66
from logging import Logger
7+
78
from traitlets import Int, Unicode
89
from traitlets.config import LoggingConfigurable
9-
10-
from ypy_websocket.stores import SQLiteYStore as _SQLiteYStore
1110
from ypy_websocket.stores import FileYStore
11+
from ypy_websocket.stores import SQLiteYStore as _SQLiteYStore
1212

1313

1414
class TempFileYStore(FileYStore):

jupyter_collaboration/websocketserver.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from tornado.websocket import WebSocketHandler
1111
from ypy_websocket.websocket_server import WebsocketServer, YRoom
12-
from ypy_websocket.stores import BaseYStore
1312

1413

1514
class RoomNotFound(LookupError):

tests/conftest.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,20 @@ def rtc_create_SQLite_store(jp_serverapp):
170170
setattr(SQLiteYStore, k, v)
171171

172172
async def _inner(type: str, path: str, content: str) -> DocumentRoom:
173-
db = SQLiteYStore(path=f"{type}:{path}")
173+
room_id = f"{type}:{path}"
174+
db = SQLiteYStore()
174175
await db.start()
176+
await db.initialize()
175177

176178
if type == "notebook":
177179
doc = YNotebook()
178180
else:
179181
doc = YUnicode()
180182

181183
doc.source = content
182-
await db.encode_state_as_update(doc.ydoc)
184+
185+
await db.create(room_id, 0)
186+
await db.encode_state_as_update(room_id, doc.ydoc)
183187

184188
return db
185189

0 commit comments

Comments
 (0)