From 8b153e2779d7d30bd67339c8e913e4d43f9ac8bf Mon Sep 17 00:00:00 2001 From: David Brochart Date: Fri, 1 Dec 2023 15:26:17 +0100 Subject: [PATCH] Set shared document file_id --- .gitignore | 3 +++ plugins/yjs/fps_yjs/routes.py | 1 + plugins/yjs/fps_yjs/ydocs/ybasedoc.py | 8 ++++++++ plugins/yjs/fps_yjs/ydocs/ynotebook.py | 2 +- pyproject.toml | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d4751320..70e4192c 100644 --- a/.gitignore +++ b/.gitignore @@ -344,3 +344,6 @@ $RECYCLE.BIN/ .jupyter_ystore.db .jupyter_ystore.db-journal fps_cli_args.toml + +# pixi environments +.pixi diff --git a/plugins/yjs/fps_yjs/routes.py b/plugins/yjs/fps_yjs/routes.py index 1ba97afb..56852885 100644 --- a/plugins/yjs/fps_yjs/routes.py +++ b/plugins/yjs/fps_yjs/routes.py @@ -181,6 +181,7 @@ async def serve(self, websocket: YWebsocket, permissions) -> None: file_path = await self.contents.file_id_manager.get_path(file_id) logger.info(f"Opening collaboration room: {websocket.path} ({file_path})") document = YDOCS.get(file_type, YFILE)(room.ydoc) + document.file_id = file_id self.documents[websocket.path] = document async with self.lock: model = await self.contents.read_content(file_path, True, file_format) diff --git a/plugins/yjs/fps_yjs/ydocs/ybasedoc.py b/plugins/yjs/fps_yjs/ydocs/ybasedoc.py index 8b68dad4..3d75d35e 100644 --- a/plugins/yjs/fps_yjs/ydocs/ybasedoc.py +++ b/plugins/yjs/fps_yjs/ydocs/ybasedoc.py @@ -51,6 +51,14 @@ def path(self) -> Optional[str]: def path(self, value: str) -> None: self._ystate["path"] = value + @property + def file_id(self) -> Optional[str]: + return self._ystate.get("file_id") + + @file_id.setter + def file_id(self, value: str) -> None: + self._ystate["file_id"] = value + @abstractmethod def get(self) -> Any: ... diff --git a/plugins/yjs/fps_yjs/ydocs/ynotebook.py b/plugins/yjs/fps_yjs/ydocs/ynotebook.py index 65cafabb..0cadd698 100644 --- a/plugins/yjs/fps_yjs/ydocs/ynotebook.py +++ b/plugins/yjs/fps_yjs/ydocs/ynotebook.py @@ -125,7 +125,7 @@ def set(self, value: Dict) -> None: # clear document self._ymeta.clear() self._ycells.clear() - for key in [k for k in self._ystate.keys() if k not in ("dirty", "path")]: + for key in [k for k in self._ystate.keys() if k not in ("dirty", "path", "file_id")]: del self._ystate[key] # initialize document diff --git a/pyproject.toml b/pyproject.toml index 418cccad..c86aacbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ test = [ "requests", "websockets", "ipykernel", - "ypywidgets >=0.6.3,<0.7.0", + "ypywidgets >=0.6.4,<0.7.0", "ypywidgets-textual >=0.2.2,<0.3.0", ] docs = [ "mkdocs", "mkdocs-material" ]