Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jupyterlite_webr/labextension
.yarn/
.jupyterlite.doit.db
jupyterlite_webr/_version.py
jupyter-lite.json
_dev
venv

# Created by https://www.gitignore.io/api/python
# Edit at https://www.gitignore.io/?templates=python
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ dependencies:
- nodejs=20
# deps
- jupyterlab >=4.0,<5
- jupyterlite-core >=0.5.0
- jupyterlite-core >=0.6.0
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@r-wasm/jupyterlite-webr-kernel",
"version": "0.5.2",
"version": "0.6.0",
"description": "An R kernel for JupyterLite, powered by webR",
"keywords": [
"jupyter",
Expand Down Expand Up @@ -60,14 +60,15 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyterlite/kernel": "^0.5.0",
"@jupyterlite/server": "^0.5.0",
"@jupyterlab/application": "^4.4.0",
"@jupyterlite/kernel": "^0.6.2",
"@jupyterlite/server": "^0.6.2",
"hash.js": "^1.1.7",
"webr": "^0.4.3"
"webr": "^0.5.1"
},
"devDependencies": {
"@jupyterlab/builder": "^4.4.1",
"@jupyterlab/coreutils": "^6.4.0",
"@jupyterlab/builder": "^4.4.3",
"@jupyterlab/coreutils": "^6.4.3",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
Expand Down Expand Up @@ -103,16 +104,13 @@
}
}
},
"jupyterlite": {
"liteExtension": true
},
"jupyter-releaser": {
"skip": [
"check-links"
],
"hooks": {
"before-build-npm": [
"python -m pip install 'jupyterlab>=4.3.0,<5'",
"python -m pip install 'jupyterlab>=4.4.0,<5'",
"jlpm"
]
}
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling>=1.5.0", "jupyterlab>=4.3.0,<4.4", "hatch-nodejs-version>=0.3.2"]
requires = ["hatchling>=1.24.0", "hatch-jupyter-builder", "jupyterlab>=4.4.0,<4.5", "hatch-nodejs-version>=0.3.2"]
build-backend = "hatchling.build"

[project]
Expand All @@ -22,14 +22,14 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = ["jupyterlite-core>=0.5,<0.6"]
dependencies = ["jupyterlite-core>=0.6,<0.7"]
dynamic = ["version", "description", "authors", "urls", "keywords"]

[project.optional-dependencies]
dev = [
"jupyterlab>=4.3.0,<4.4",
"jupyterlab>=4.4.0,<4.5",
"ruff==0.1.5",
"jupyterlite-pyodide-kernel>=0.5.2",
"jupyterlite-pyodide-kernel>=0.6.1",
"pkginfo>=1.10.0",
]

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

[tool.hatch.build.hooks.jupyter-builder]
dependencies = ["hatch-jupyter-builder>=0.5"]
dependencies = ["hatch-jupyter-builder>=0.9"]
build-function = "hatch_jupyter_builder.npm_builder"
ensured-targets = [
"jupyterlite_webr/labextension/static/style.js",
Expand Down Expand Up @@ -79,7 +79,7 @@ version_cmd = "hatch version"

[tool.jupyter-releaser.hooks]
before-build-npm = [
"python -m pip install 'jupyterlab>=4.3.0,<4.4'",
"python -m pip install 'jupyterlab>=4.4.0,<4.5'",
"jlpm",
"jlpm build:prod"
]
Expand Down
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { JupyterLiteServer, JupyterLiteServerPlugin } from '@jupyterlite/server';
import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
import { IKernel, IKernelSpecs } from '@jupyterlite/kernel';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { WebRKernel } from './webr_kernel';
import logo32 from '!!file-loader?context=.!../style/logos/r-logo-32x32.png';
import logo64 from '!!file-loader?context=.!../style/logos/r-logo-64x64.png';
import type { WebROptions } from 'webr';
import { IServiceWorkerManager } from '@jupyterlite/server';

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

const server_kernel: JupyterLiteServerPlugin<void> = {
const server_kernel: JupyterFrontEndPlugin<void> = {
id: PLUGIN_ID,
autoStart: true,
requires: [IKernelSpecs],
activate: (app: JupyterLiteServer, kernelspecs: IKernelSpecs) => {
optional: [IServiceWorkerManager],
activate: (
app: JupyterFrontEnd,
kernelspecs: IKernelSpecs,
serviceWorkerManager: IServiceWorkerManager | null
) => {
const config = JSON.parse(
PageConfig.getOption('litePluginSettings') || '{}'
)[PLUGIN_ID] || {};
Expand Down Expand Up @@ -53,11 +59,11 @@ const server_kernel: JupyterLiteServerPlugin<void> = {
},
},
create: async (options: IKernel.IOptions): Promise<IKernel> => {
return new WebRKernel({ ...options }, webROptions);
return new WebRKernel({ ...options }, webROptions, serviceWorkerManager);
},
});
},
};

const plugins: JupyterLiteServerPlugin<any>[] = [server_kernel];
const plugins: JupyterFrontEndPlugin<any>[] = [server_kernel];
export default plugins;
8 changes: 7 additions & 1 deletion src/webr_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IKernel } from '@jupyterlite/kernel';

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

const protocolVersion = "5.3";

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

constructor(options: IKernel.IOptions, webROptions: WebROptions) {
constructor(
options: IKernel.IOptions,
webROptions: WebROptions,
private serviceWorkerManager: IServiceWorkerManager | null
) {
super(options);
this.#webRConsole = new Console({
stdout: (line: string) => console.log(line),
Expand Down Expand Up @@ -57,6 +62,7 @@ export class WebRKernel extends BaseKernel {

// Mount Jupyterlite storage and set the CWD
await this.webR.evalRVoid(`
options(webr.drivefs.browsingContextId = "${this.serviceWorkerManager?.browsingContextId}")
webr::mount("/drive", type="DRIVEFS")
setwd("/drive")
`);
Expand Down
Loading