Skip to content

Commit

Permalink
pre-commit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsailer committed Apr 29, 2024
1 parent 59a011a commit 8d52c58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
24 changes: 6 additions & 18 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ async def open(self, room_id):
self.log.error(f"File {file.path} not found.\n{e!r}", exc_info=e)
self.close(1004, f"File {file.path} not found.")
else:
self.log.error(
f"Error initializing: {file.path}\n{e!r}", exc_info=e
)
self.log.error(f"Error initializing: {file.path}\n{e!r}", exc_info=e)
self.close(
1003,
f"Error initializing: {file.path}. You need to close the document.",
Expand Down Expand Up @@ -306,14 +304,10 @@ async def on_message(self, message):
for client in self.room.clients:
if client != self:
task = asyncio.create_task(
client.send(
bytes([MessageType.CHAT]) + write_var_uint(len(data)) + data
)
client.send(bytes([MessageType.CHAT]) + write_var_uint(len(data)) + data)
)
self._websocket_server.background_tasks.add(task)
task.add_done_callback(
self._websocket_server.background_tasks.discard
)
task.add_done_callback(self._websocket_server.background_tasks.discard)

self._message_queue.put_nowait(message)
self._websocket_server.ypatch_nb += 1
Expand All @@ -332,9 +326,7 @@ def on_close(self) -> None:
if self._room_id != "JupyterLab:globalAwareness":
self._emit_awareness_event(self.current_user.username, "leave")

def _emit(
self, level: LogLevel, action: str | None = None, msg: str | None = None
) -> None:
def _emit(self, level: LogLevel, action: str | None = None, msg: str | None = None) -> None:
_, _, file_id = decode_file_path(self._room_id)
path = self._file_id_manager.get_path(file_id)

Expand All @@ -346,16 +338,12 @@ def _emit(

self.event_logger.emit(schema_id=JUPYTER_COLLABORATION_EVENTS_URI, data=data)

def _emit_awareness_event(
self, username: str, action: str, msg: str | None = None
) -> None:
def _emit_awareness_event(self, username: str, action: str, msg: str | None = None) -> None:
data = {"roomid": self._room_id, "username": username, "action": action}
if msg:
data["msg"] = msg

self.event_logger.emit(
schema_id=JUPYTER_COLLABORATION_AWARENESS_EVENTS_URI, data=data
)
self.event_logger.emit(schema_id=JUPYTER_COLLABORATION_AWARENESS_EVENTS_URI, data=data)

async def _clean_room(self) -> None:
"""
Expand Down
20 changes: 5 additions & 15 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ async def initialize(self) -> None:
self.ready = True
self._emit(LogLevel.INFO, "initialize", "Room initialized")

def _emit(
self, level: LogLevel, action: str | None = None, msg: str | None = None
) -> None:
def _emit(self, level: LogLevel, action: str | None = None, msg: str | None = None) -> None:
data = {"level": level.value, "room": self._room_id, "path": self._file.path}
if action:
data["action"] = action
Expand Down Expand Up @@ -186,12 +184,8 @@ async def _on_outofband_change(self) -> None:
"""
Called when the file got out-of-band changes.
"""
self.log.info(
"Out-of-band changes. Overwriting the content in room %s", self._room_id
)
self._emit(
LogLevel.INFO, "overwrite", "Out-of-band changes. Overwriting the room."
)
self.log.info("Out-of-band changes. Overwriting the content in room %s", self._room_id)
self._emit(LogLevel.INFO, "overwrite", "Out-of-band changes. Overwriting the room.")

try:
model = await self._file.load_content(self._file_format, self._file_type)
Expand Down Expand Up @@ -267,13 +261,9 @@ async def _maybe_save_document(self, saving_document: asyncio.Task | None) -> No
return

except OutOfBandChanges:
self.log.info(
"Out-of-band changes. Overwriting the content in room %s", self._room_id
)
self.log.info("Out-of-band changes. Overwriting the content in room %s", self._room_id)
try:
model = await self._file.load_content(
self._file_format, self._file_type
)
model = await self._file.load_content(self._file_format, self._file_type)
except Exception as e:
msg = f"Error loading content from file: {self._file.path}\n{e!r}"
self.log.error(msg, exc_info=e)
Expand Down

0 comments on commit 8d52c58

Please sign in to comment.