From f8e74fffb2ab5fd5df6be7d73d6e0d981b10fab1 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Wed, 8 Jan 2025 15:09:58 +0100 Subject: [PATCH] - --- .github/workflows/test.yml | 1 + jupyter_ydoc/ybasedoc.py | 8 ++++---- jupyter_ydoc/yblob.py | 2 +- jupyter_ydoc/ynotebook.py | 18 ++++++++++-------- pyproject.toml | 3 ++- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84c155f..385af14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,6 +49,7 @@ jobs: run: | micromamba install pip nodejs=18 pip install ".[test]" + pip install "pycrdt >=0.12.1" - name: Build JavaScript assets working-directory: javascript run: | diff --git a/jupyter_ydoc/ybasedoc.py b/jupyter_ydoc/ybasedoc.py index 9560b1e..ee8c5c7 100644 --- a/jupyter_ydoc/ybasedoc.py +++ b/jupyter_ydoc/ybasedoc.py @@ -29,7 +29,7 @@ class YBaseDoc(ABC): _ydoc: YDoc _ystate: YState - _subscriptions: Dict[Any, Subscription] + _subscriptions: dict[Any, Subscription] _undo_manager: UndoManager def __init__(self, ydoc: YDoc | Doc | None = None, awareness: Awareness | None = None): @@ -121,7 +121,7 @@ def dirty(self) -> bool | None: """ try: return self._ystate.dirty - except: + except AttributeError: return None @dirty.setter @@ -144,7 +144,7 @@ def hash(self) -> str | None: """ try: return self._ystate.hash - except: + except AttributeError: return None @hash.setter @@ -167,7 +167,7 @@ def path(self) -> str | None: """ try: return self._ystate.path - except: + except AttributeError: return None @path.setter diff --git a/jupyter_ydoc/yblob.py b/jupyter_ydoc/yblob.py index 0472723..a282ec6 100644 --- a/jupyter_ydoc/yblob.py +++ b/jupyter_ydoc/yblob.py @@ -70,7 +70,7 @@ def get(self) -> bytes: """ try: return self._ysource.bytes - except: + except AttributeError: return b"" def set(self, value: bytes) -> None: diff --git a/jupyter_ydoc/ynotebook.py b/jupyter_ydoc/ynotebook.py index 81c41ce..a98dfb4 100644 --- a/jupyter_ydoc/ynotebook.py +++ b/jupyter_ydoc/ynotebook.py @@ -141,7 +141,7 @@ def cell_number(self) -> int: """ return len(self._ycells) - def get_cell(self, index: int) -> Dict[str, Any]: + def get_cell(self, index: int) -> dict[str, Any]: """ Returns a cell. @@ -166,7 +166,7 @@ def get_cell(self, index: int) -> Dict[str, Any]: del cell["attachments"] return cell - def append_cell(self, value: Dict[str, Any]) -> None: + def append_cell(self, value: dict[str, Any]) -> None: """ Appends a cell. @@ -176,7 +176,7 @@ def append_cell(self, value: Dict[str, Any]) -> None: ycell = self.create_ycell(value) self._ycells.append(ycell) - def set_cell(self, index: int, value: Dict[str, Any]) -> None: + def set_cell(self, index: int, value: dict[str, Any]) -> None: """ Sets a cell into indicated position. @@ -189,7 +189,7 @@ def set_cell(self, index: int, value: Dict[str, Any]) -> None: ycell = self.create_ycell(value) self.set_ycell(index, ycell) - def create_ycell(self, value: Dict[str, Any]) -> YCell: + def create_ycell(self, value: dict[str, Any]) -> YCell: """ Creates YCell with the content of the cell. @@ -239,7 +239,7 @@ def set_ycell(self, index: int, ycell: YCell) -> None: """ self._ycells[index] = ycell - def get(self) -> Dict: + def get(self) -> dict: """ Returns the content of the document. @@ -269,7 +269,7 @@ def get(self) -> Dict: nbformat_minor=int(meta.get("nbformat_minor", 0)), ) - def set(self, value: Dict) -> None: + def set(self, value: dict) -> None: """ Sets the content of the document. @@ -306,9 +306,11 @@ def set(self, value: Dict) -> None: ymetadata = YMetadata() self._ymeta.metadata = ymetadata metadata = nb.get("metadata", {}) - # ymetadata.language_info = asdict(LanguageInfo(**metadata.get("language_info", {"name": ""}))) + # ymetadata.language_info = + # asdict(LanguageInfo(**metadata.get("language_info", {"name": ""}))) ymetadata.language_info = metadata.get("language_info", {"name": ""}) - # ymetadata.kernelspec = asdict(Kernelspec(**metadata.get("kernelspec", {"name": "", "display_name": ""}))) + # ymetadata.kernelspec = + # asdict(Kernelspec(**metadata.get("kernelspec", {"name": "", "display_name": ""}))) ymetadata.kernelspec = metadata.get("kernelspec", {"name": "", "display_name": ""}) def observe(self, callback: Callable[[str, Any], None]) -> None: diff --git a/pyproject.toml b/pyproject.toml index 0d95e8f..6e4c456 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,8 @@ requires-python = ">=3.8" keywords = ["jupyter", "pycrdt", "yjs"] dependencies = [ "importlib_metadata >=3.6; python_version<'3.10'", - "pycrdt >=0.12.1,<0.13.0", + # "pycrdt >=0.12.1,<0.13.0", + "pycrdt >=0.10.1,<0.11.0", ] [[project.authors]]