Skip to content

Commit

Permalink
Bump jupytercad
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Feb 27, 2024
1 parent a7b16fb commit e25810e
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
shell: bash -l {0}
run: |
set -eux
pip install "jupyterlab>=4.0.0,<5" "jupytercad>=1.0.0a3" jupytercad_freecad*.whl
pip install "jupyterlab>=4.0.0,<5" "jupytercad>=2.0.0a1" jupytercad_freecad*.whl
- name: Install dependencies
shell: bash -l {0}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_galata_references.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
shell: bash -l {0}
run: |
whereis python
pip install "jupyterlab>=4.0.0,<5" "jupytercad>=1.0.0a3" jupytercad_freecad*.whl
pip install "jupyterlab>=4.0.0,<5" "jupytercad>=2.0.0a1" jupytercad_freecad*.whl
- name: Install dependencies
shell: bash -l {0}
Expand Down
40 changes: 19 additions & 21 deletions jupytercad_freecad/fcstd_ydoc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
from typing import Any, Callable
from functools import partial

import y_py as Y
from pycrdt import Array, Map, Text
from jupyter_ydoc.ybasedoc import YBaseDoc

from .freecad.loader import FCStd
Expand All @@ -11,23 +10,23 @@
class YFCStd(YBaseDoc):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._ysource = self._ydoc.get_text("source")
self._yobjects = self._ydoc.get_array("objects")
self._yoptions = self._ydoc.get_map("options")
self._ymeta = self._ydoc.get_map("metadata")
self._ydoc["source"] = self._ysource = Text()
self._ydoc["objects"] = self._yobjects = Array()
self._ydoc["options"] = self._yoptions = Map()
self._ydoc["metadata"] = self._ymetadata = Map()
self._virtual_file = FCStd()

@property
def objects(self) -> Y.YArray:
def objects(self) -> Array:
return self._yobjects

def version(self) -> str:
return "0.1.0"

def get(self):
fc_objects = json.loads(self._yobjects.to_json())
options = json.loads(self._yoptions.to_json())
meta = json.loads(self._ymeta.to_json())
fc_objects = self._yobjects.to_py()
options = self._yoptions.to_py()
meta = self._ymetadata.to_py()

self._virtual_file.save(fc_objects, options, meta)
return self._virtual_file.sources
Expand All @@ -38,16 +37,15 @@ def set(self, value):
objects = []

for obj in virtual_file.objects:
objects.append(Y.YMap(obj))
with self._ydoc.begin_transaction() as t:
length = len(self._yobjects)
self._yobjects.delete_range(t, 0, length)
# workaround for https://github.com/y-crdt/ypy/issues/126:
# self._yobjects.extend(t, objects)
for o in objects:
self._yobjects.append(t, o)
self._yoptions.update(t, virtual_file.options.items())
self._ymeta.update(t, virtual_file.metadata.items())
objects.append(Map(obj))
self._yobjects.clear()
self._yobjects.extend(objects)

self._yoptions.clear()
self._yoptions.update(virtual_file.options)

self._ymetadata.clear()
self._ymetadata.update(virtual_file.metadata)

def observe(self, callback: Callable[[str, Any], None]):
self.unobserve()
Expand All @@ -63,6 +61,6 @@ def observe(self, callback: Callable[[str, Any], None]):
self._subscriptions[self._yoptions] = self._yoptions.observe_deep(
partial(callback, "options")
)
self._subscriptions[self._ymeta] = self._ymeta.observe_deep(
self._subscriptions[self._ymetadata] = self._ymetadata.observe_deep(
partial(callback, "meta")
)
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyter/collaboration": "^1.0.0",
"@jupyter/docprovider": "^1.0.0",
"@jupytercad/base": "^1.0.0",
"@jupytercad/jupytercad-core": "^1.0.0",
"@jupytercad/schema": "^1.0.0",
"@jupyter/collaboration": "^2.0.0",
"@jupyter/docprovider": "^2.0.0",
"@jupytercad/base": "^2.0.0-alpha.1",
"@jupytercad/jupytercad-core": "^2.0.0-alpha.1",
"@jupytercad/schema": "^2.0.0-alpha.1",
"@jupyterlab/application": "^4.0.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
"jupyter_ydoc>=1.1.0,<2",
"y-py>=0.6.0,<0.7",
"jupytercad_core>=1.0.0,<2",
"jupyter_ydoc>=2,<3",
"jupytercad_core>=2.0.0a1,<3",
]
dynamic = ["version", "description", "authors", "urls", "keywords"]

Expand Down
Loading

0 comments on commit e25810e

Please sign in to comment.