Skip to content

Commit 24a17cd

Browse files
authored
Rewrite as JupyterLab frontend plugin (#49)
* Rewrite as JupyterLab frontend plugin * Fix deployment dependencies * Update to jupyterlab 4.4.0 and juoyterlite-core 0.6.0a6 * Hard pin of jupyterlite-core 0.6.0a6 * Terminal shutdown * Linting * Update ui-tests * Lint tests * Update test images * Update to jupyterlite-core 0.6.0-alpha.9 * Use browsingContextId for drive access * Use latest pre-releases in CI * Separate plugin to set browsingContextId * Update to lite 0.6.0a10 * Update to lite 0.6.0b0
1 parent 1a0639d commit 24a17cd

18 files changed

+2105
-1866
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
- name: Install the extension
107107
run: |
108108
set -eux
109-
python -m pip install --pre "jupyterlite-core>=0.4,<0.5" "jupyterlab>=4,<5" jupyterlite_terminal*.whl
109+
python -m pip install --pre "jupyterlite-core==0.6.0b0" "jupyterlab>=4,<5" jupyterlite_terminal*.whl
110110
111111
- name: Micromamba needed for cockle_wasm_env
112112
uses: mamba-org/setup-micromamba@main

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- name: Install the dependencies
2424
run: |
25-
python -m pip install --pre "jupyterlite-core>=0.4,<0.5" jupyterlite-pyodide-kernel
25+
python -m pip install --pre "jupyterlite-core==0.6.0b0" "jupyterlite-pyodide-kernel==0.6.0b1"
2626
2727
# install a dev version of the terminal extension
2828
python -m pip install .

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

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

3636
- name: Install dependencies
37-
run: python -m pip install -U --pre "jupyterlite-core>=0.4,<0.5" "jupyterlab>=4,<5"
37+
run: python -m pip install -U --pre "jupyterlite-core==0.6.0b0" "jupyterlab>=4,<5"
3838

3939
- name: Install extension
4040
run: |

deploy/jupyter-lite.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"jupyter-lite-schema-version": 0,
33
"jupyter-config-data": {
4+
"disabledExtensions": ["@jupyterlab/services-extension:terminal-manager"],
45
"terminalsAvailable": true
56
}
67
}

deploy/requirements-deploy.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jupyterlab>=4,<5
2-
jupyterlite-core>=0.4,<0.5
3-
jupyterlite-pyodide-kernel
1+
jupyterlab
2+
jupyterlite-core==0.6.0b0
3+
jupyterlite-pyodide-kernel==0.6.0b1
44
..

package.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@
5959
"watch:labextension": "jupyter labextension watch ."
6060
},
6161
"dependencies": {
62-
"@jupyterlab/coreutils": "^6.3.5",
63-
"@jupyterlab/services": "^7.3.5",
64-
"@jupyterlab/terminal": "^4.3.5",
65-
"@jupyterlab/terminal-extension": "^4.3.5",
66-
"@jupyterlite/cockle": "^0.0.18",
67-
"@jupyterlite/contents": "^0.5.1",
68-
"@jupyterlite/server": "^0.5.1",
62+
"@jupyterlab/coreutils": "^6.4.2",
63+
"@jupyterlab/services": "^7.4.2",
64+
"@jupyterlab/terminal": "^4.4.2",
65+
"@jupyterlab/terminal-extension": "^4.4.2",
66+
"@jupyterlite/cockle": "^0.0.19",
67+
"@jupyterlite/contents": "0.6.0-beta.0",
68+
"@jupyterlite/server": "0.6.0-beta.0",
6969
"@lumino/coreutils": "^2.2.0",
7070
"mock-socket": "^9.3.1"
7171
},
7272
"devDependencies": {
73-
"@jupyterlab/builder": "^4.3.5",
74-
"@jupyterlab/testutils": "^4.3.5",
73+
"@jupyterlab/builder": "^4.4.2",
74+
"@jupyterlab/testutils": "^4.4.2",
7575
"@types/jest": "^29.2.0",
7676
"@types/json-schema": "^7.0.11",
7777
"@types/react": "^18.0.26",
@@ -111,9 +111,6 @@
111111
"extension": true,
112112
"outputDir": "jupyterlite_terminal/labextension"
113113
},
114-
"jupyterlite": {
115-
"liteExtension": true
116-
},
117114
"eslintIgnore": [
118115
"node_modules",
119116
"dist",

src/index.ts

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,58 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
import {
5-
JupyterLiteServer,
6-
JupyterLiteServerPlugin,
7-
Router
8-
} from '@jupyterlite/server';
5+
JupyterFrontEnd,
6+
JupyterFrontEndPlugin
7+
} from '@jupyterlab/application';
8+
import {
9+
ITerminalManager,
10+
ServiceManagerPlugin,
11+
Terminal
12+
} from '@jupyterlab/services';
13+
import { IServiceWorkerManager } from '@jupyterlite/server';
914

10-
import { TerminalManager } from './manager';
11-
import { ITerminalManager } from './tokens';
15+
import { isILiteTerminalManager, LiteTerminalManager } from './manager';
1216

1317
/**
14-
* The terminals service plugin.
18+
* The terminal manager plugin, replacing the JupyterLab terminal manager.
1519
*/
16-
const terminalsPlugin: JupyterLiteServerPlugin<ITerminalManager> = {
20+
const terminalManagerPlugin: ServiceManagerPlugin<Terminal.IManager> = {
1721
id: '@jupyterlite/terminal:plugin',
18-
description: 'A terminal for JupyterLite',
22+
description: 'A JupyterLite extension providing a custom terminal manager',
1923
autoStart: true,
2024
provides: ITerminalManager,
21-
activate: async (app: JupyterLiteServer) => {
25+
activate: (_: null): Terminal.IManager => {
2226
console.log(
2327
'JupyterLite extension @jupyterlite/terminal:plugin is activated!'
2428
);
25-
26-
const { serviceManager } = app;
27-
const { serverSettings, terminals } = serviceManager;
28-
console.log('terminals available:', terminals.isAvailable());
29-
console.log('terminals ready:', terminals.isReady); // Not ready
30-
console.log('terminals active:', terminals.isActive);
31-
32-
// Not sure this is necessary?
33-
await terminals.ready;
34-
console.log('terminals ready after await:', terminals.isReady); // Ready
35-
36-
return new TerminalManager(serverSettings.wsUrl);
29+
return new LiteTerminalManager();
3730
}
3831
};
3932

4033
/**
41-
* A plugin providing the routes for the terminals service
34+
* A plugin that sets the browsingContextId of the terminal manager.
4235
*/
43-
const terminalsRoutesPlugin: JupyterLiteServerPlugin<void> = {
44-
id: '@jupyterlite/terminal:routes-plugin',
36+
const browsingContextIdSetter: JupyterFrontEndPlugin<void> = {
37+
id: '@jupyterlite/terminal:browsing-context-id',
4538
autoStart: true,
39+
optional: [IServiceWorkerManager],
4640
requires: [ITerminalManager],
47-
activate: (app: JupyterLiteServer, terminalManager: ITerminalManager) => {
48-
console.log(
49-
'JupyterLite extension @jupyterlite/terminal:routes-plugin is activated!',
50-
terminalManager
51-
);
52-
53-
// GET /api/terminals - List the running terminals
54-
app.router.get('/api/terminals', async (req: Router.IRequest) => {
55-
const res = await terminalManager.listRunning();
56-
// Should return last_activity for each too,
57-
return new Response(JSON.stringify(res));
58-
});
59-
60-
// POST /api/terminals - Start a terminal
61-
app.router.post('/api/terminals', async (req: Router.IRequest) => {
62-
const res = await terminalManager.startNew();
63-
// Should return last_activity too.
64-
return new Response(JSON.stringify(res));
65-
});
66-
67-
// DELETE /api/terminals/{terminal name} - Delete a terminal
68-
app.router.delete(
69-
'/api/terminals/(.+)',
70-
async (req: Router.IRequest, name: string) => {
71-
const exists = terminalManager.has(name);
72-
if (exists) {
73-
await terminalManager.shutdownTerminal(name);
74-
} else {
75-
const msg = `The terminal session "${name}"" does not exist`;
76-
console.warn(msg);
77-
}
78-
79-
return new Response(null, { status: exists ? 204 : 404 });
41+
activate: (
42+
_: JupyterFrontEnd,
43+
terminalManager: Terminal.IManager,
44+
serviceWorkerManager?: IServiceWorkerManager
45+
): void => {
46+
if (serviceWorkerManager !== undefined) {
47+
if (isILiteTerminalManager(terminalManager)) {
48+
const { browsingContextId } = serviceWorkerManager;
49+
terminalManager.browsingContextId = browsingContextId;
50+
} else {
51+
console.warn(
52+
'Terminal manager does not support setting browsingContextId'
53+
);
8054
}
81-
);
55+
}
8256
}
8357
};
8458

85-
export default [terminalsPlugin, terminalsRoutesPlugin];
59+
export default [terminalManagerPlugin, browsingContextIdSetter];

0 commit comments

Comments
 (0)