Skip to content

Commit 11d0e14

Browse files
authored
Update jupyterlite 0.6.0-alpha.3: remove split liteextension/labextension (#204)
* Remove split liteextension/labextension * Linter * Update docs * Update docs * Iterate * Try * Update lite * Lower bound jupyterlite
1 parent edb0594 commit 11d0e14

File tree

15 files changed

+647
-754
lines changed

15 files changed

+647
-754
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
sudo rm -rf $(which node)
8282
sudo rm -rf $(which node)
8383
84-
pip install "jupyterlab>=4.0.0,<4.3" jupyterlite_xeus*.whl
84+
pip install "jupyterlab>=4.4.0.b0,<5" jupyterlite_xeus*.whl
8585
8686
jupyter labextension list
8787
jupyter labextension list 2>&1 | grep -ie "@jupyterlite/xeus.*OK"
@@ -149,7 +149,7 @@ jobs:
149149
- name: Install the extension
150150
run: |
151151
set -eux
152-
python -m pip install "jupyterlab>=4.0.0,<4.3" jupyterlite_xeus*.whl
152+
python -m pip install "jupyterlab>=4.4.0.b0,<5" jupyterlite_xeus*.whl
153153
python -m pip install ${{ matrix.jupyterlite_version }}
154154
155155
- name: Install dependencies

.github/workflows/update-integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
4040

4141
- name: Install dependencies
42-
run: python -m pip install -U "jupyterlab>=4.0.0,<4.3" jupyterlite-core
42+
run: python -m pip install -U "jupyterlab>=4.4.0.b0,<5" jupyterlite-core
4343

4444
- name: Install extension
4545
run: |

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ node_modules/
66
*.egg-info/
77
.ipynb_checkpoints
88
*.tsbuildinfo
9-
jupyterlite_xeus/liteextension
109
jupyterlite_xeus/labextension
1110
# Version file is handled by hatchling
1211
jupyterlite_xeus/_version.py

docs/build-environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ dependencies:
1414
- myst-parser
1515
- sphinx-design
1616
- pydata-sphinx-theme
17-
- jupyterlab >=4.0.5,<5
18-
- jupyterlite-core >=0.5,<0.6
1917
- jupyterlite-sphinx >=0.13.1
2018
- empack >=3.1.0
2119
- pip:
20+
- jupyterlab >=4.4.0.b0,<5
21+
- jupyterlite-core >=0.6.0.a3,<0.7
2222
- ..

jupyterlite_xeus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212

1313
def _jupyter_labextension_paths():
14-
return [{"src": "labextension", "dest": "@jupyterlite/xeus"}, {"src": "liteextension", "dest": "@jupyterlite/xeus-kernels-extension"}]
14+
return [{"src": "labextension", "dest": "@jupyterlite/xeus"}]

packages/xeus-kernels-extension/lab.webpack.config.js renamed to packages/xeus-extension/lab.webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const staticPath = [
1616
'..',
1717
'..',
1818
'jupyterlite_xeus',
19-
'liteextension',
19+
'labextension',
2020
'static',
2121
'[name].wasm'
2222
];

packages/xeus-extension/package.json

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@
4141
"watch:labextension": "jupyter labextension watch ."
4242
},
4343
"dependencies": {
44-
"@jupyterlab/application": "^4.3.4",
45-
"@jupyterlab/coreutils": "^6",
46-
"@jupyterlab/logconsole": "^4.3.5",
47-
"@jupyterlab/notebook": "^4.3.5",
44+
"@jupyterlab/application": "^4.4.0-beta.0",
45+
"@jupyterlab/coreutils": "^6.4.0-beta.0",
46+
"@jupyterlab/logconsole": "^4.4.0-beta.0",
47+
"@jupyterlab/notebook": "^4.4.0-beta.0",
48+
"@jupyterlite/contents": "^0.6.0-alpha.4",
49+
"@jupyterlite/kernel": "^0.6.0-alpha.4",
50+
"@jupyterlite/server": "^0.6.0-alpha.4",
4851
"@jupyterlite/xeus": "^4.0.0-a1",
4952
"@lumino/coreutils": "^2"
5053
},
5154
"devDependencies": {
52-
"@jupyterlab/builder": "^4.1.0",
55+
"@jupyterlab/builder": "^4.4.0-beta.0",
5356
"@types/json-schema": "^7.0.11",
5457
"@types/react": "^18.0.26",
5558
"@types/react-addons-linked-state-mixin": "^0.14.22",
@@ -74,6 +77,21 @@
7477
"jupyterlab": {
7578
"extension": true,
7679
"schemaDir": "schema",
77-
"outputDir": "../../jupyterlite_xeus/labextension"
80+
"outputDir": "../../jupyterlite_xeus/labextension",
81+
"webpackConfig": "lab.webpack.config.js",
82+
"sharedPackages": {
83+
"@jupyterlite/kernel": {
84+
"bundled": false,
85+
"singleton": true
86+
},
87+
"@jupyterlite/server": {
88+
"bundled": false,
89+
"singleton": true
90+
},
91+
"@jupyterlite/contents": {
92+
"bundled": false,
93+
"singleton": true
94+
}
95+
}
7896
}
7997
}

packages/xeus-extension/src/index.ts

Lines changed: 127 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ import {
66
JupyterFrontEndPlugin,
77
JupyterFrontEnd
88
} from '@jupyterlab/application';
9-
109
import {
1110
MainAreaWidget,
1211
IToolbarWidgetRegistry,
1312
showErrorMessage
1413
} from '@jupyterlab/apputils';
15-
1614
import { listIcon, ToolbarButton } from '@jupyterlab/ui-components';
17-
1815
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
19-
2016
import { LoggerRegistry, LogConsolePanel } from '@jupyterlab/logconsole';
21-
2217
import { NotebookPanel } from '@jupyterlab/notebook';
18+
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
19+
20+
import { IServiceWorkerManager } from '@jupyterlite/server';
21+
import { IBroadcastChannelWrapper } from '@jupyterlite/contents';
22+
import { IKernel, IKernelSpecs } from '@jupyterlite/kernel';
23+
24+
const xeus = await import('@jupyterlite/xeus');
25+
26+
import { IEmpackEnvMetaFile } from './tokens';
2327

2428
enum KernelStatus {
2529
None = 0,
@@ -28,6 +32,122 @@ enum KernelStatus {
2832
Error = 3
2933
}
3034

35+
/**
36+
* Fetches JSON data from the specified URL asynchronously.
37+
*
38+
* This function constructs the full URL using the base URL from the PageConfig and
39+
* the provided relative URL. It then performs a GET request using the Fetch API
40+
* and returns the parsed JSON data.
41+
*
42+
* @param {string} url - The relative URL to fetch the JSON data from.
43+
* @returns {Promise<any>} - A promise that resolves to the parsed JSON data.
44+
* @throws {Error} - Throws an error if the HTTP request fails.
45+
*
46+
*/
47+
async function getJson(url: string) {
48+
const jsonUrl = URLExt.join(PageConfig.getBaseUrl(), url);
49+
const response = await fetch(jsonUrl, { method: 'GET' });
50+
51+
if (!response.ok) {
52+
throw new Error(`HTTP error! status: ${response.status}`);
53+
}
54+
55+
const data = await response.json();
56+
return data;
57+
}
58+
59+
const kernelPlugin: JupyterFrontEndPlugin<void> = {
60+
id: '@jupyterlite/xeus-kernel:register',
61+
autoStart: true,
62+
requires: [IKernelSpecs],
63+
optional: [
64+
IServiceWorkerManager,
65+
IBroadcastChannelWrapper,
66+
IEmpackEnvMetaFile
67+
],
68+
activate: async (
69+
app: JupyterFrontEnd,
70+
kernelspecs: IKernelSpecs,
71+
serviceWorker?: IServiceWorkerManager,
72+
broadcastChannel?: IBroadcastChannelWrapper,
73+
empackEnvMetaFile?: IEmpackEnvMetaFile
74+
) => {
75+
// Fetch kernel list
76+
let kernelList: string[] = [];
77+
try {
78+
kernelList = await getJson('xeus/kernels.json');
79+
} catch (err) {
80+
console.log(`Could not fetch xeus/kernels.json: ${err}`);
81+
throw err;
82+
}
83+
const contentsManager = app.serviceManager.contents;
84+
85+
for (const kernel of kernelList) {
86+
// Fetch kernel spec
87+
const kernelspec = await getJson(
88+
'xeus/kernels/' + kernel + '/kernel.json'
89+
);
90+
kernelspec.name = kernel;
91+
kernelspec.dir = kernel;
92+
for (const [key, value] of Object.entries(kernelspec.resources)) {
93+
kernelspec.resources[key] = URLExt.join(
94+
PageConfig.getBaseUrl(),
95+
value as string
96+
);
97+
}
98+
kernelspecs.register({
99+
spec: kernelspec,
100+
create: async (options: IKernel.IOptions): Promise<IKernel> => {
101+
const mountDrive = !!(
102+
(serviceWorker?.enabled && broadcastChannel?.enabled) ||
103+
crossOriginIsolated
104+
);
105+
106+
if (mountDrive) {
107+
console.info(
108+
`${kernelspec.name} contents will be synced with Jupyter Contents`
109+
);
110+
} else {
111+
console.warn(
112+
`${kernelspec.name} contents will NOT be synced with Jupyter Contents`
113+
);
114+
}
115+
const link = empackEnvMetaFile
116+
? await empackEnvMetaFile.getLink(kernelspec)
117+
: '';
118+
119+
return new xeus.WebWorkerKernel({
120+
...options,
121+
contentsManager,
122+
mountDrive,
123+
kernelSpec: kernelspec,
124+
empackEnvMetaLink: link
125+
});
126+
}
127+
});
128+
}
129+
await app.serviceManager.kernelspecs.refreshSpecs();
130+
}
131+
};
132+
133+
const empackEnvMetaPlugin: JupyterFrontEndPlugin<IEmpackEnvMetaFile> = {
134+
id: '@jupyterlite/xeus:empack-env-meta',
135+
autoStart: true,
136+
provides: IEmpackEnvMetaFile,
137+
activate: (): IEmpackEnvMetaFile => {
138+
return {
139+
getLink: async (kernelspec: Record<string, any>) => {
140+
const kernelName = kernelspec.name;
141+
const kernel_root_url = URLExt.join(
142+
PageConfig.getBaseUrl(),
143+
`xeus/kernels/${kernelName}`
144+
);
145+
return `${kernel_root_url}`;
146+
}
147+
};
148+
}
149+
};
150+
31151
const kernelStatusPlugin: JupyterFrontEndPlugin<void> = {
32152
id: '@jupyterlite/xeus-extension:xeus-kernel-status',
33153
autoStart: true,
@@ -190,4 +310,5 @@ const kernelStatusPlugin: JupyterFrontEndPlugin<void> = {
190310
}
191311
};
192312

193-
export default [kernelStatusPlugin];
313+
export default [kernelStatusPlugin, empackEnvMetaPlugin, kernelPlugin];
314+
export { IEmpackEnvMetaFile };

packages/xeus-kernels-extension/package.json

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)