-
Notifications
You must be signed in to change notification settings - Fork 8
Add mypy type checking for rooms/ module
#133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Typing Checks | ||
|
|
||
| on: | ||
| push: | ||
| # IMPORTANT: update these paths when we expand type-checking coverage | ||
| branches: [main] | ||
| paths: | ||
| - 'jupyter_server_documents/rooms/**' | ||
| - '.github/workflows/typing-checks.yml' | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'jupyter_server_documents/rooms/**' | ||
| - '.github/workflows/typing-checks.yml' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| python: | ||
| name: 'Python' | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ['3.10', '3.11', '3.12', '3.13'] | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Base Setup | ||
| uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 | ||
| with: | ||
| python_version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install mypy | ||
| python -m pip install -e .[test] | ||
|
|
||
| - name: Type-check `rooms` module | ||
| run: | | ||
| mypy jupyter_server_documents/rooms |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from .yroom import YRoom | ||
| from typing import TYPE_CHECKING | ||
| from typing import cast, TYPE_CHECKING | ||
| import asyncio | ||
| import traitlets | ||
| from traitlets.config import LoggingConfigurable | ||
| from jupyter_server_fileid.manager import BaseFileIdManager | ||
| from jupyter_server_fileid.manager import BaseFileIdManager # type: ignore | ||
|
|
||
| from ..outputs.manager import OutputsManager | ||
|
|
||
| if TYPE_CHECKING: | ||
| import logging | ||
| from typing import Set | ||
| from jupyter_server.extension.application import ExtensionApp | ||
| from jupyter_server.services.contents.manager import ContentsManager | ||
| from jupyter_events import EventLogger | ||
|
|
@@ -53,7 +54,7 @@ class YRoomManager(LoggingConfigurable): | |
| this declaration only hints the type for type checkers. | ||
| """ | ||
|
|
||
| _rooms_by_id: dict[str, YRoom] = traitlets.Dict(default_value={}) | ||
| _rooms_by_id: traitlets.Dict[str, YRoom] = traitlets.Dict(default_value={}) | ||
| """ | ||
| Dictionary of active `YRoom` instances, keyed by room ID. Rooms are never | ||
| deleted from this dictionary. | ||
|
|
@@ -62,11 +63,12 @@ class YRoomManager(LoggingConfigurable): | |
| out-of-band. See #116. | ||
| """ | ||
|
|
||
| _inactive_rooms: set[str] = traitlets.Set() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this isn't possible. |
||
| _inactive_rooms = traitlets.Set() | ||
| """ | ||
| Set of room IDs that were marked inactive on the last iteration of | ||
| `_watch_rooms()`. If a room is inactive and its ID is present in this set, | ||
| then the room should be restarted as it has been inactive for >10 seconds. | ||
| Set of room IDs (as strings) that were marked inactive on the last iteration | ||
| of `_watch_rooms()`. If a room is inactive and its ID is present in this | ||
| set, then the room should be restarted as it has been inactive for >10 | ||
| seconds. | ||
| """ | ||
|
|
||
| _watch_rooms_task: asyncio.Task | None | ||
|
|
@@ -84,23 +86,34 @@ def __init__(self, *args, **kwargs): | |
|
|
||
| @property | ||
| def fileid_manager(self) -> BaseFileIdManager: | ||
| if self.parent.serverapp is None: | ||
| raise RuntimeError("ServerApp is not available") | ||
| manager = self.parent.serverapp.web_app.settings.get("file_id_manager", None) | ||
| assert isinstance(manager, BaseFileIdManager) | ||
| return manager | ||
|
|
||
|
|
||
| @property | ||
| def contents_manager(self) -> ContentsManager: | ||
| if self.parent.serverapp is None: | ||
| raise RuntimeError("ServerApp is not available") | ||
| return self.parent.serverapp.contents_manager | ||
|
|
||
|
|
||
| @property | ||
| def event_logger(self) -> EventLogger: | ||
| return self.parent.serverapp.event_logger | ||
| if self.parent.serverapp is None: | ||
| raise RuntimeError("ServerApp is not available") | ||
| event_logger = self.parent.serverapp.event_logger | ||
| if event_logger is None: | ||
| raise RuntimeError("Event logger is not available") | ||
| return event_logger | ||
|
|
||
|
|
||
| @property | ||
| def outputs_manager(self) -> OutputsManager: | ||
| if not hasattr(self.parent, 'outputs_manager'): | ||
| raise RuntimeError("Outputs manager is not available") | ||
| return self.parent.outputs_manager | ||
|
|
||
|
|
||
|
|
@@ -156,17 +169,17 @@ def delete_room(self, room_id: str) -> None: | |
| """ | ||
| yroom = self._rooms_by_id.pop(room_id, None) | ||
| if not yroom: | ||
| return | ||
| return None | ||
|
|
||
| self.log.info(f"Stopping YRoom '{room_id}'.") | ||
| try: | ||
| yroom.stop() | ||
| return True | ||
| return None | ||
| except Exception as e: | ||
| self.log.exception( | ||
| f"Exception raised when stopping YRoom '{room_id}: " | ||
| ) | ||
| return False | ||
| return None | ||
|
|
||
|
|
||
| async def _watch_rooms(self) -> None: | ||
|
|
@@ -274,9 +287,9 @@ async def stop(self) -> None: | |
|
|
||
| # Define task that deletes the room and waits until the content is saved | ||
| async def delete_then_save(room_id: str, room: YRoom): | ||
| ret = self.delete_room(room_id) | ||
| self.delete_room(room_id) | ||
| await room.until_saved | ||
| return ret | ||
| return None | ||
|
|
||
| # Delete all rooms concurrently using `delete_then_save()` | ||
| for room_id, room in self._rooms_by_id.items(): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.