Skip to content

Commit ead4456

Browse files
Support for JupyterLite 0.6 (#17)
* Update JupyterLab to 4.4 and JupyterLite to 0.6 * Set browsing context ID when mounting JupyterLite * Upgrade to webR v0.5.1 * Final newlines --------- Co-authored-by: Tony Hirst <[email protected]>
1 parent 4c8bbdf commit ead4456

File tree

7 files changed

+906
-489
lines changed

7 files changed

+906
-489
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jupyterlite_webr/labextension
1010
.yarn/
1111
.jupyterlite.doit.db
1212
jupyterlite_webr/_version.py
13+
jupyter-lite.json
14+
_dev
15+
venv
1316

1417
# Created by https://www.gitignore.io/api/python
1518
# Edit at https://www.gitignore.io/?templates=python

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ dependencies:
1212
- nodejs=20
1313
# deps
1414
- jupyterlab >=4.0,<5
15-
- jupyterlite-core >=0.5.0
15+
- jupyterlite-core >=0.6.0

package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@r-wasm/jupyterlite-webr-kernel",
3-
"version": "0.5.2",
3+
"version": "0.6.0",
44
"description": "An R kernel for JupyterLite, powered by webR",
55
"keywords": [
66
"jupyter",
@@ -60,14 +60,15 @@
6060
"watch:labextension": "jupyter labextension watch ."
6161
},
6262
"dependencies": {
63-
"@jupyterlite/kernel": "^0.5.0",
64-
"@jupyterlite/server": "^0.5.0",
63+
"@jupyterlab/application": "^4.4.0",
64+
"@jupyterlite/kernel": "^0.6.2",
65+
"@jupyterlite/server": "^0.6.2",
6566
"hash.js": "^1.1.7",
66-
"webr": "^0.4.3"
67+
"webr": "^0.5.1"
6768
},
6869
"devDependencies": {
69-
"@jupyterlab/builder": "^4.4.1",
70-
"@jupyterlab/coreutils": "^6.4.0",
70+
"@jupyterlab/builder": "^4.4.3",
71+
"@jupyterlab/coreutils": "^6.4.3",
7172
"@types/uuid": "^9.0.0",
7273
"@typescript-eslint/eslint-plugin": "^4.8.1",
7374
"@typescript-eslint/parser": "^4.8.1",
@@ -103,16 +104,13 @@
103104
}
104105
}
105106
},
106-
"jupyterlite": {
107-
"liteExtension": true
108-
},
109107
"jupyter-releaser": {
110108
"skip": [
111109
"check-links"
112110
],
113111
"hooks": {
114112
"before-build-npm": [
115-
"python -m pip install 'jupyterlab>=4.3.0,<5'",
113+
"python -m pip install 'jupyterlab>=4.4.0,<5'",
116114
"jlpm"
117115
]
118116
}

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling>=1.5.0", "jupyterlab>=4.3.0,<4.4", "hatch-nodejs-version>=0.3.2"]
2+
requires = ["hatchling>=1.24.0", "hatch-jupyter-builder", "jupyterlab>=4.4.0,<4.5", "hatch-nodejs-version>=0.3.2"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -22,14 +22,14 @@ classifiers = [
2222
"Programming Language :: Python :: 3.12",
2323
"Programming Language :: Python :: 3.13",
2424
]
25-
dependencies = ["jupyterlite-core>=0.5,<0.6"]
25+
dependencies = ["jupyterlite-core>=0.6,<0.7"]
2626
dynamic = ["version", "description", "authors", "urls", "keywords"]
2727

2828
[project.optional-dependencies]
2929
dev = [
30-
"jupyterlab>=4.3.0,<4.4",
30+
"jupyterlab>=4.4.0,<4.5",
3131
"ruff==0.1.5",
32-
"jupyterlite-pyodide-kernel>=0.5.2",
32+
"jupyterlite-pyodide-kernel>=0.6.1",
3333
"pkginfo>=1.10.0",
3434
]
3535

@@ -51,7 +51,7 @@ exclude = [".github"]
5151
path = "jupyterlite_webr/_version.py"
5252

5353
[tool.hatch.build.hooks.jupyter-builder]
54-
dependencies = ["hatch-jupyter-builder>=0.5"]
54+
dependencies = ["hatch-jupyter-builder>=0.9"]
5555
build-function = "hatch_jupyter_builder.npm_builder"
5656
ensured-targets = [
5757
"jupyterlite_webr/labextension/static/style.js",
@@ -79,7 +79,7 @@ version_cmd = "hatch version"
7979

8080
[tool.jupyter-releaser.hooks]
8181
before-build-npm = [
82-
"python -m pip install 'jupyterlab>=4.3.0,<4.4'",
82+
"python -m pip install 'jupyterlab>=4.4.0,<4.5'",
8383
"jlpm",
8484
"jlpm build:prod"
8585
]

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
import { JupyterLiteServer, JupyterLiteServerPlugin } from '@jupyterlite/server';
1+
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
22
import { IKernel, IKernelSpecs } from '@jupyterlite/kernel';
33
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
44
import { WebRKernel } from './webr_kernel';
55
import logo32 from '!!file-loader?context=.!../style/logos/r-logo-32x32.png';
66
import logo64 from '!!file-loader?context=.!../style/logos/r-logo-64x64.png';
77
import type { WebROptions } from 'webr';
8+
import { IServiceWorkerManager } from '@jupyterlite/server';
89

910
const PLUGIN_ID = '@r-wasm/webr-kernel-extension:kernel';
1011

11-
const server_kernel: JupyterLiteServerPlugin<void> = {
12+
const server_kernel: JupyterFrontEndPlugin<void> = {
1213
id: PLUGIN_ID,
1314
autoStart: true,
1415
requires: [IKernelSpecs],
15-
activate: (app: JupyterLiteServer, kernelspecs: IKernelSpecs) => {
16+
optional: [IServiceWorkerManager],
17+
activate: (
18+
app: JupyterFrontEnd,
19+
kernelspecs: IKernelSpecs,
20+
serviceWorkerManager: IServiceWorkerManager | null
21+
) => {
1622
const config = JSON.parse(
1723
PageConfig.getOption('litePluginSettings') || '{}'
1824
)[PLUGIN_ID] || {};
@@ -53,11 +59,11 @@ const server_kernel: JupyterLiteServerPlugin<void> = {
5359
},
5460
},
5561
create: async (options: IKernel.IOptions): Promise<IKernel> => {
56-
return new WebRKernel({ ...options }, webROptions);
62+
return new WebRKernel({ ...options }, webROptions, serviceWorkerManager);
5763
},
5864
});
5965
},
6066
};
6167

62-
const plugins: JupyterLiteServerPlugin<any>[] = [server_kernel];
68+
const plugins: JupyterFrontEndPlugin<any>[] = [server_kernel];
6369
export default plugins;

src/webr_kernel.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IKernel } from '@jupyterlite/kernel';
44

55
import { Console, WebR, Shelter, WebROptions } from 'webr';
66
import { RList, RCharacter, RLogical } from 'webr';
7+
import { IServiceWorkerManager } from '@jupyterlite/server';
78

89
const protocolVersion = "5.3";
910

@@ -15,7 +16,11 @@ export class WebRKernel extends BaseKernel {
1516
#bitmapCanvas: HTMLCanvasElement;
1617
#lastPlot: string | null = null;
1718

18-
constructor(options: IKernel.IOptions, webROptions: WebROptions) {
19+
constructor(
20+
options: IKernel.IOptions,
21+
webROptions: WebROptions,
22+
private serviceWorkerManager: IServiceWorkerManager | null
23+
) {
1924
super(options);
2025
this.#webRConsole = new Console({
2126
stdout: (line: string) => console.log(line),
@@ -57,6 +62,7 @@ export class WebRKernel extends BaseKernel {
5762

5863
// Mount Jupyterlite storage and set the CWD
5964
await this.webR.evalRVoid(`
65+
options(webr.drivefs.browsingContextId = "${this.serviceWorkerManager?.browsingContextId}")
6066
webr::mount("/drive", type="DRIVEFS")
6167
setwd("/drive")
6268
`);

0 commit comments

Comments
 (0)