Skip to content

Commit 1611a56

Browse files
Enable Python API in the JupyterLite deployment (#680)
* Config docs * Revert changes * Update lite env * update lite config * Bump yjs-widgets and make changes wrt * Update lite/environment.yml Co-authored-by: martinRenou <[email protected]> * bump yjs-widgets on jupytercad_app too * use updated version of actions/cache * try building jcad in lite * try installing whl instead from src * try giving a random name to the wheels to be used for lite * correct path * not needed * move collaboration to jupytercad * do same for lab * No need to install * install jupyter-server in CI * typo * lazily import `setup_handlers` * install jupytercad metapackage for ui tests * install metapackage in correct job * build jupytercad metapackage too * try adding docprovider to sharedPackages * not needed * try bundled true --------- Co-authored-by: martinRenou <[email protected]>
1 parent f5c86a2 commit 1611a56

File tree

19 files changed

+107
-84
lines changed

19 files changed

+107
-84
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
yarn=3
2626
2727
- name: Setup pip cache
28-
uses: actions/cache@v2
28+
uses: actions/cache@v4
2929
with:
3030
path: ~/.cache/pip
3131
key: pip-3.9-${{ hashFiles('package.json') }}
@@ -38,7 +38,7 @@ jobs:
3838
run: echo "::set-output name=dir::$(yarn cache dir)"
3939

4040
- name: Setup yarn cache
41-
uses: actions/cache@v2
41+
uses: actions/cache@v4
4242
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
4343
with:
4444
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
@@ -47,7 +47,7 @@ jobs:
4747
yarn-
4848
4949
- name: Setup OpenCascade build cache
50-
uses: actions/cache@v2
50+
uses: actions/cache@v4
5151
with:
5252
path: |
5353
packages/opencascade/lib/jupytercad.opencascade.js
@@ -84,6 +84,7 @@ jobs:
8484
python/jupytercad_core/dist/jupytercad*
8585
python/jupytercad_lab/dist/jupytercad*
8686
python/jupytercad_app/dist/jupytercad*
87+
python/jupytercad/dist/jupytercad*
8788
if-no-files-found: error
8889

8990
test_isolated:
@@ -148,7 +149,7 @@ jobs:
148149
shell: bash -l {0}
149150
run: |
150151
set -eux
151-
cp ./jupytercad_core/dist/jupytercad*.whl ./jupytercad_lab/dist/jupytercad*.whl ./jupytercad_app/dist/jupytercad*.whl .
152+
cp ./jupytercad_core/dist/jupytercad*.whl ./jupytercad_lab/dist/jupytercad*.whl ./jupytercad_app/dist/jupytercad*.whl ./jupytercad/dist/jupytercad*.whl .
152153
python -m pip install jupytercad*.whl
153154
154155
- name: Install dependencies
@@ -159,7 +160,7 @@ jobs:
159160
run: jlpm install
160161

161162
- name: Set up browser cache
162-
uses: actions/cache@v3
163+
uses: actions/cache@v4
163164
with:
164165
path: |
165166
${{ github.workspace }}/pw-browsers
@@ -221,6 +222,7 @@ jobs:
221222
pip
222223
jupyterlite-core
223224
jupyterlite-xeus
225+
jupyter_server
224226
225227
- name: Download extension package
226228
uses: actions/download-artifact@v4
@@ -231,15 +233,16 @@ jobs:
231233
shell: bash -l {0}
232234
run: |
233235
set -eux
234-
cp ./jupytercad_core/dist/jupytercad*.whl ./jupytercad_lab/dist/jupytercad*.whl ./jupytercad_app/dist/jupytercad*.whl .
235-
python -m pip install jupytercad*.whl
236+
cp ./jupytercad_core/dist/jupytercad*.whl jupytercad_core-0.0.1-py3-none-any.whl
237+
cp ./jupytercad_lab/dist/jupytercad*.whl jupytercad_lab-0.0.1-py3-none-any.whl
238+
cp ./jupytercad_app/dist/jupytercad*.whl jupytercad_app-0.0.1-py3-none-any.whl
236239
237240
- name: Build the lite site
238241
shell: bash -l {0}
239242
working-directory: lite
240243
run: |
241244
set -eux
242-
mkdir -p content && cp ../examples/*.jcad ../examples/*.STEP ../examples/*.stl ./content
245+
mkdir -p content && cp ../examples/*.jcad ../examples/*.STEP ../examples/*.stl ../examples/*.ipynb ./content
243246
jupyter lite build --contents content --output-dir dist
244247
245248
- name: Upload github-pages artifact

lite/environment.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
name: xeus-python-kernel
22
channels:
3-
- https://repo.mamba.pm/emscripten-forge
4-
- conda-forge
3+
- https://prefix.dev/emscripten-forge-dev
4+
- https://prefix.dev/conda-forge
55
dependencies:
6+
- python=3.13
7+
- pip
68
- xeus-python
9+
- requests
10+
- jupyter_ydoc=2.1.5
11+
- ypywidgets>=0.9.6,<0.10.0
12+
- comm>=0.1.2,<0.2.0
13+
- pydantic>=2,<3
14+
- pip:
15+
- yjs-widgets>=0.4,<0.5
16+
- my-jupyter-shared-drive
17+
- ../jupytercad_core-0.0.1-py3-none-any.whl
18+
- ../jupytercad_lab-0.0.1-py3-none-any.whl

lite/jupyter-lite.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
22
"jupyter-lite-schema-version": 0,
3-
"jupyter-config-data": {
4-
"appName": "My JupyterCAD App",
5-
"disabledExtensions": [
6-
"@jupyter/collaboration-extension",
7-
"@jupyter/docprovider-extension"
8-
]
9-
}
3+
"jupyter-config-data": {}
104
}

packages/base/src/widget.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ export class JupyterCadPanel extends SplitPanel {
268268

269269
(this._consoleTracker.widgetAdded as any).emit(consolePanel);
270270
await consolePanel.sessionContext.ready;
271-
await consolePanel.console.inject(
272-
`from jupytercad_lab import CadDocument\ndoc = CadDocument("${jcadPath}")`
273-
);
274271
this.addWidget(this._consoleView);
275272
this.setRelativeSizes([2, 1]);
276273
this._consoleOpened = true;
274+
await consolePanel.console.inject(
275+
`from jupytercad_lab import CadDocument\ndoc = CadDocument("${jcadPath}")`
276+
);
277277
consolePanel.console.sessionContext.kernelChanged.connect((_, arg) => {
278278
if (!arg.newValue) {
279279
this.removeConsole();

python/jupytercad/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies = [
2222
"jupytercad_core==3.0.1",
2323
"jupytercad_lab==3.0.1",
2424
"jupytercad_app==3.0.1",
25+
"jupyter-collaboration>=3,<4",
26+
"jupyterlab>=4.3,<5",
2527
]
2628
dynamic = ["version"]
2729
license = {file = "LICENSE"}

python/jupytercad_app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"@lumino/widgets": "^2.0.0",
109109
"react": "^18.0.1",
110110
"yjs": "^13.5.40",
111-
"yjs-widgets": "^0.3.7"
111+
"yjs-widgets": "^0.4"
112112
},
113113
"devDependencies": {
114114
"@jupyterlab/builder": "^4.0.0",

python/jupytercad_core/jupytercad_core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
warnings.warn("Importing 'jupytercad_core' outside a proper installation.")
1010
__version__ = "dev"
1111

12-
from .handlers import setup_handlers
13-
1412

1513
def _jupyter_labextension_paths():
1614
return [{"src": "labextension", "dest": "@jupytercad/jupytercad-core"}]
@@ -24,5 +22,7 @@ def _load_jupyter_server_extension(server_app):
2422
server_app: jupyterlab.labapp.LabApp
2523
JupyterLab application instance
2624
"""
25+
from .handlers import setup_handlers
26+
2727
setup_handlers(server_app.web_app)
2828
server_app.log.info("Registered jupytercad server extension")

python/jupytercad_core/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3.12",
2020
]
2121
dependencies = [
22-
"jupyter_server>=2.0.6,<3",
2322
"jupyter_ydoc>=2,<4",
24-
"jupyter-collaboration>=3.1.0,<4",
2523
"pydantic>=2,<3",
2624
]
2725
dynamic = ["version", "description", "authors", "urls", "keywords"]

python/jupytercad_core/src/jcadplugin/modelfactory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export class JupyterCadJcadModelFactory
1919
/**
2020
* Whether the model is collaborative or not.
2121
*/
22-
readonly collaborative =
23-
document.querySelectorAll('[data-jupyter-lite-root]')[0] === undefined;
22+
readonly collaborative = true;
2423

2524
/**
2625
* The name of the model.

python/jupytercad_core/src/stepplugin/modelfactory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export class JupyterCadStepModelFactory
2323
/**
2424
* Whether the model is collaborative or not.
2525
*/
26-
readonly collaborative =
27-
document.querySelectorAll('[data-jupyter-lite-root]')[0] === undefined;
26+
readonly collaborative = true;
2827

2928
/**
3029
* The name of the model.

0 commit comments

Comments
 (0)