git: baffb7be56d9 - main - devel/py-jupyter-ydoc: Allow build with py-pycrdt 0.9.0+

From: Po-Chuan Hsieh <sunpoet_at_FreeBSD.org>
Date: Sun, 07 Jul 2024 17:23:46 UTC
The branch main has been updated by sunpoet:

URL: https://cgit.FreeBSD.org/ports/commit/?id=baffb7be56d9141bad9fa846a52b3b0d94574a4f

commit baffb7be56d9141bad9fa846a52b3b0d94574a4f
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2024-07-07 17:20:53 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2024-07-07 17:20:53 +0000

    devel/py-jupyter-ydoc: Allow build with py-pycrdt 0.9.0+
    
    - Bump PORTREVISION for package change
    
    Obtained from:  https://github.com/jupyter-server/jupyter_ydoc/commit/803631dc5e771bd441b285373574f573b5c7f664
                    https://github.com/jupyter-server/jupyter_ydoc/commit/1466ca2f94915876590f802b03c39b69e225d672
                    https://github.com/jupyter-server/jupyter_ydoc/commit/8e3f25bdcfb8ed36cd740dd958d5d04580cd54ef
---
 devel/py-jupyter-ydoc/Makefile           |   3 +-
 devel/py-jupyter-ydoc/files/patch-pycrdt | 122 +++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/devel/py-jupyter-ydoc/Makefile b/devel/py-jupyter-ydoc/Makefile
index 0ed67a817456..7fad394ef639 100644
--- a/devel/py-jupyter-ydoc/Makefile
+++ b/devel/py-jupyter-ydoc/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	jupyter-ydoc
 PORTVERSION=	2.0.1
+PORTREVISION=	1
 CATEGORIES=	devel python
 MASTER_SITES=	PYPI \
 		https://github.com/jupyter-server/jupyter_ydoc/releases/download/v${PORTVERSION}/
@@ -16,7 +17,7 @@ LICENSE_FILE=	${WRKSRC}/LICENSE
 
 BUILD_DEPENDS=	${PYTHON_PKGNAMEPREFIX}hatch-nodejs-version>=0:devel/py-hatch-nodejs-version@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}hatchling>=1.10.0:devel/py-hatchling@${PY_FLAVOR}
-RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}pycrdt>=0.8.1<0.9.0:devel/py-pycrdt@${PY_FLAVOR}
+RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}pycrdt>=0.9.0<0.10.0:devel/py-pycrdt@${PY_FLAVOR}
 
 USES=		python
 USE_PYTHON=	autoplist concurrent pep517
diff --git a/devel/py-jupyter-ydoc/files/patch-pycrdt b/devel/py-jupyter-ydoc/files/patch-pycrdt
new file mode 100644
index 000000000000..4ddf4e3a153b
--- /dev/null
+++ b/devel/py-jupyter-ydoc/files/patch-pycrdt
@@ -0,0 +1,122 @@
+--- jupyter_ydoc/__init__.py.orig	2020-02-02 00:00:00 UTC
++++ jupyter_ydoc/__init__.py
+@@ -3,11 +3,11 @@ import sys
+ 
+ import sys
+ 
+-from ._version import __version__  # noqa
+-from .yblob import YBlob  # noqa
+-from .yfile import YFile  # noqa
+-from .ynotebook import YNotebook  # noqa
+-from .yunicode import YUnicode  # noqa
++from ._version import __version__ as __version__
++from .yblob import YBlob as YBlob
++from .yfile import YFile as YFile
++from .ynotebook import YNotebook as YNotebook
++from .yunicode import YUnicode as YUnicode
+ 
+ # See compatibility note on `group` keyword in
+ # https://docs.python.org/3/library/importlib.metadata.html#entry-points
+--- jupyter_ydoc/ybasedoc.py.orig	2020-02-02 00:00:00 UTC
++++ jupyter_ydoc/ybasedoc.py
+@@ -2,9 +2,9 @@ from abc import ABC, abstractmethod
+ # Distributed under the terms of the Modified BSD License.
+ 
+ from abc import ABC, abstractmethod
+-from typing import Any, Callable, Dict, Optional
++from typing import Any, Callable, Optional
+ 
+-from pycrdt import Doc, Map
++from pycrdt import Doc, Map, Subscription, UndoManager
+ 
+ 
+ class YBaseDoc(ABC):
+@@ -15,6 +15,11 @@ class YBaseDoc(ABC):
+     subscribe to changes in the document.
+     """
+ 
++    _ydoc: Doc
++    _ystate: Map
++    _subscriptions: dict[Any, Subscription]
++    _undo_manager: UndoManager
++
+     def __init__(self, ydoc: Optional[Doc] = None):
+         """
+         Constructs a YBaseDoc.
+@@ -26,8 +31,9 @@ class YBaseDoc(ABC):
+             self._ydoc = Doc()
+         else:
+             self._ydoc = ydoc
+-        self._ydoc["state"] = self._ystate = Map()
+-        self._subscriptions: Dict[Any, str] = {}
++        self._ystate = self._ydoc.get("state", type=Map)
++        self._subscriptions = {}
++        self._undo_manager = UndoManager(doc=self._ydoc, capture_timeout_millis=0)
+ 
+     @property
+     @abstractmethod
+@@ -40,6 +46,15 @@ class YBaseDoc(ABC):
+         """
+ 
+     @property
++    def undo_manager(self) -> UndoManager:
++        """
++        A :class:`pycrdt.UndoManager` for the document.
++
++        :return: The document's undo manager.
++        :rtype: :class:`pycrdt.UndoManager`
++        """
++        return self._undo_manager
++
+     def ystate(self) -> Map:
+         """
+         A :class:`pycrdt.Map` containing the state of the document.
+--- jupyter_ydoc/yblob.py.orig	2020-02-02 00:00:00 UTC
++++ jupyter_ydoc/yblob.py
+@@ -36,7 +36,8 @@ class YBlob(YBaseDoc):
+         :type ydoc: :class:`pycrdt.Doc`, optional.
+         """
+         super().__init__(ydoc)
+-        self._ydoc["source"] = self._ysource = Map()
++        self._ysource = self._ydoc.get("source", type=Map)
++        self.undo_manager.expand_scope(self._ysource)
+ 
+     @property
+     def version(self) -> str:
+--- jupyter_ydoc/ynotebook.py.orig	2020-02-02 00:00:00 UTC
++++ jupyter_ydoc/ynotebook.py
+@@ -54,8 +54,9 @@ class YNotebook(YBaseDoc):
+         :type ydoc: :class:`pycrdt.Doc`, optional.
+         """
+         super().__init__(ydoc)
+-        self._ydoc["meta"] = self._ymeta = Map()
+-        self._ydoc["cells"] = self._ycells = Array()
++        self._ymeta = self._ydoc.get("meta", type=Map)
++        self._ycells = self._ydoc.get("cells", type=Array)
++        self.undo_manager.expand_scope(self._ycells)
+ 
+     @property
+     def version(self) -> str:
+--- jupyter_ydoc/yunicode.py.orig	2020-02-02 00:00:00 UTC
++++ jupyter_ydoc/yunicode.py
+@@ -31,7 +31,8 @@ class YUnicode(YBaseDoc):
+         :type ydoc: :class:`pycrdt.Doc`, optional.
+         """
+         super().__init__(ydoc)
+-        self._ydoc["source"] = self._ysource = Text()
++        self._ysource = self._ydoc.get("source", type=Text)
++        self.undo_manager.expand_scope(self._ysource)
+ 
+     @property
+     def version(self) -> str:
+--- pyproject.toml.orig	2020-02-02 00:00:00 UTC
++++ pyproject.toml
+@@ -13,7 +13,7 @@ dependencies = [
+ keywords = ["jupyter", "ypy"]
+ dependencies = [
+     "importlib_metadata >=3.6; python_version<'3.10'",
+-    "pycrdt >=0.8.1,<0.9.0",
++    "pycrdt >=0.9.0,<0.10.0",
+ ]
+ 
+ [[project.authors]]