Skip to content

Commit

Permalink
Bump jupytercad (#8)
Browse files Browse the repository at this point in the history
* Bump jupytercad

* Update UI tests
  • Loading branch information
trungleduc authored Feb 28, 2024
1 parent a7b16fb commit 9f98946
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 112 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
2 changes: 1 addition & 1 deletion ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test:debug": "PWDEBUG=1 npx playwright test"
},
"devDependencies": {
"@jupyterlab/galata": "^5.0.8",
"@jupyterlab/galata": "^5.1.0",
"@playwright/test": "^1.32.0",
"@types/klaw-sync": "^6.0.1"
},
Expand Down
22 changes: 8 additions & 14 deletions ui-tests/tests/ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,17 @@ test.describe('UI Test', () => {
await page.notebook.openByPath(fullPath);
await page.notebook.activate(fullPath);
await page.locator('div.jpcad-Spinner').waitFor({ state: 'hidden' });
const btn = await page.locator(
"button.jp-ToolbarButtonComponent[data-command='jupytercad:newBox']"
);
await btn.click();

await page.getByTitle('New Box').click();

const nameInput = await page.locator(
'input[id^="id-jp-schemaform"][label="Name"]'
);
nameInput.fill('Foo');
await nameInput.fill('Foo');
const accept = await page.locator('div.jp-Dialog-buttonLabel', {
hasText: 'Submit'
});
accept.click();
await accept.click();

await page
.getByRole('tablist', { name: 'main sidebar' })
Expand Down Expand Up @@ -248,10 +247,8 @@ test.describe('UI Test', () => {
await page.locator('div.jpcad-Spinner').waitFor({ state: 'hidden' });

// Create a cone
const btn = await page.locator(
"button.jp-ToolbarButtonComponent[data-command='jupytercad:newCone']"
);
await btn.click();
await page.getByTitle('New Cone').click();

await page.getByLabel('Radius1').click();
await page.getByLabel('Radius1').fill('15');
await page.getByLabel('Radius2').click();
Expand Down Expand Up @@ -287,10 +284,7 @@ test.describe('UI Test', () => {
await page.waitForTimeout(1000);

// Apply a cut operator from the selection
const cutbtn = await page.locator(
"button.jp-ToolbarButtonComponent[data-command='jupytercad:cut']"
);
await cutbtn.click();
await page.getByTitle('Cut', { exact: true }).click();
await page
.locator('.jp-Dialog-body')
.locator('div.jp-Dialog-buttonLabel', {
Expand Down
Loading

0 comments on commit 9f98946

Please sign in to comment.