@jupyterlite/pyodide-kernel 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_pypi.d.ts +6 -0
- package/lib/_pypi.js +7 -0
- package/lib/comlink.worker.d.ts +1 -0
- package/lib/comlink.worker.js +9 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +7 -0
- package/lib/kernel.d.ts +132 -0
- package/lib/kernel.js +245 -0
- package/lib/tokens.d.ts +56 -0
- package/lib/tokens.js +3 -0
- package/lib/worker.d.ts +134 -0
- package/lib/worker.js +32 -0
- package/lib/worker.js.map +7 -0
- package/package.json +82 -0
- package/pypi/all.json +128 -0
- package/pypi/ipykernel-6.9.2-py3-none-any.whl +0 -0
- package/pypi/piplite-0.0.2-py3-none-any.whl +0 -0
- package/pypi/pyodide_kernel-0.0.2-py3-none-any.whl +0 -0
- package/pypi/widgetsnbextension-3.6.0-py3-none-any.whl +0 -0
- package/pypi/widgetsnbextension-4.0.2-py3-none-any.whl +0 -0
- package/style/base.css +4 -0
- package/style/index.css +6 -0
- package/style/index.js +6 -0
package/lib/_pypi.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * as allJSONUrl from '../pypi/all.json';
|
|
2
|
+
export * as ipykernelWheelUrl from '../pypi/ipykernel-6.9.2-py3-none-any.whl';
|
|
3
|
+
export * as pipliteWheelUrl from '../pypi/piplite-0.0.2-py3-none-any.whl';
|
|
4
|
+
export * as pyodide_kernelWheelUrl from '../pypi/pyodide_kernel-0.0.2-py3-none-any.whl';
|
|
5
|
+
export * as widgetsnbextensionWheelUrl from '../pypi/widgetsnbextension-3.6.0-py3-none-any.whl';
|
|
6
|
+
export * as widgetsnbextensionWheelUrl1 from '../pypi/widgetsnbextension-4.0.2-py3-none-any.whl';
|
package/lib/_pypi.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// this file is autogenerated from the wheels described in ../package.json
|
|
2
|
+
export * as allJSONUrl from '../pypi/all.json';
|
|
3
|
+
export * as ipykernelWheelUrl from '../pypi/ipykernel-6.9.2-py3-none-any.whl';
|
|
4
|
+
export * as pipliteWheelUrl from '../pypi/piplite-0.0.2-py3-none-any.whl';
|
|
5
|
+
export * as pyodide_kernelWheelUrl from '../pypi/pyodide_kernel-0.0.2-py3-none-any.whl';
|
|
6
|
+
export * as widgetsnbextensionWheelUrl from '../pypi/widgetsnbextension-3.6.0-py3-none-any.whl';
|
|
7
|
+
export * as widgetsnbextensionWheelUrl1 from '../pypi/widgetsnbextension-4.0.2-py3-none-any.whl';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
/**
|
|
4
|
+
* A WebWorker entrypoint that uses comlink to handle postMessage details
|
|
5
|
+
*/
|
|
6
|
+
import { expose } from 'comlink';
|
|
7
|
+
import { PyodideRemoteKernel } from './worker';
|
|
8
|
+
const worker = new PyodideRemoteKernel();
|
|
9
|
+
expose(worker);
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/kernel.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { KernelMessage } from '@jupyterlab/services';
|
|
2
|
+
import { BaseKernel, IKernel } from '@jupyterlite/kernel';
|
|
3
|
+
import { IPyodideWorkerKernel } from './tokens';
|
|
4
|
+
/**
|
|
5
|
+
* A kernel that executes Python code with Pyodide.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PyodideKernel extends BaseKernel implements IKernel {
|
|
8
|
+
/**
|
|
9
|
+
* Instantiate a new PyodideKernel
|
|
10
|
+
*
|
|
11
|
+
* @param options The instantiation options for a new PyodideKernel
|
|
12
|
+
*/
|
|
13
|
+
constructor(options: PyodideKernel.IOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Load the worker.
|
|
16
|
+
*
|
|
17
|
+
* ### Note
|
|
18
|
+
*
|
|
19
|
+
* Subclasses must implement this typographically almost _exactly_ for
|
|
20
|
+
* webpack to find it.
|
|
21
|
+
*/
|
|
22
|
+
protected initWorker(options: PyodideKernel.IOptions): Worker;
|
|
23
|
+
protected initRemote(options: PyodideKernel.IOptions): Promise<void>;
|
|
24
|
+
protected initRemoteOptions(options: PyodideKernel.IOptions): IPyodideWorkerKernel.IOptions;
|
|
25
|
+
/**
|
|
26
|
+
* Dispose the kernel.
|
|
27
|
+
*/
|
|
28
|
+
dispose(): void;
|
|
29
|
+
/**
|
|
30
|
+
* A promise that is fulfilled when the kernel is ready.
|
|
31
|
+
*/
|
|
32
|
+
get ready(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Process a message coming from the pyodide web worker.
|
|
35
|
+
*
|
|
36
|
+
* @param msg The worker message to process.
|
|
37
|
+
*/
|
|
38
|
+
private _processWorkerMessage;
|
|
39
|
+
/**
|
|
40
|
+
* Handle a kernel_info_request message
|
|
41
|
+
*/
|
|
42
|
+
kernelInfoRequest(): Promise<KernelMessage.IInfoReplyMsg['content']>;
|
|
43
|
+
/**
|
|
44
|
+
* Handle an `execute_request` message
|
|
45
|
+
*
|
|
46
|
+
* @param msg The parent message.
|
|
47
|
+
*/
|
|
48
|
+
executeRequest(content: KernelMessage.IExecuteRequestMsg['content']): Promise<KernelMessage.IExecuteReplyMsg['content']>;
|
|
49
|
+
/**
|
|
50
|
+
* Handle an complete_request message
|
|
51
|
+
*
|
|
52
|
+
* @param msg The parent message.
|
|
53
|
+
*/
|
|
54
|
+
completeRequest(content: KernelMessage.ICompleteRequestMsg['content']): Promise<KernelMessage.ICompleteReplyMsg['content']>;
|
|
55
|
+
/**
|
|
56
|
+
* Handle an `inspect_request` message.
|
|
57
|
+
*
|
|
58
|
+
* @param content - The content of the request.
|
|
59
|
+
*
|
|
60
|
+
* @returns A promise that resolves with the response message.
|
|
61
|
+
*/
|
|
62
|
+
inspectRequest(content: KernelMessage.IInspectRequestMsg['content']): Promise<KernelMessage.IInspectReplyMsg['content']>;
|
|
63
|
+
/**
|
|
64
|
+
* Handle an `is_complete_request` message.
|
|
65
|
+
*
|
|
66
|
+
* @param content - The content of the request.
|
|
67
|
+
*
|
|
68
|
+
* @returns A promise that resolves with the response message.
|
|
69
|
+
*/
|
|
70
|
+
isCompleteRequest(content: KernelMessage.IIsCompleteRequestMsg['content']): Promise<KernelMessage.IIsCompleteReplyMsg['content']>;
|
|
71
|
+
/**
|
|
72
|
+
* Handle a `comm_info_request` message.
|
|
73
|
+
*
|
|
74
|
+
* @param content - The content of the request.
|
|
75
|
+
*
|
|
76
|
+
* @returns A promise that resolves with the response message.
|
|
77
|
+
*/
|
|
78
|
+
commInfoRequest(content: KernelMessage.ICommInfoRequestMsg['content']): Promise<KernelMessage.ICommInfoReplyMsg['content']>;
|
|
79
|
+
/**
|
|
80
|
+
* Send an `comm_open` message.
|
|
81
|
+
*
|
|
82
|
+
* @param msg - The comm_open message.
|
|
83
|
+
*/
|
|
84
|
+
commOpen(msg: KernelMessage.ICommOpenMsg): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Send an `comm_msg` message.
|
|
87
|
+
*
|
|
88
|
+
* @param msg - The comm_msg message.
|
|
89
|
+
*/
|
|
90
|
+
commMsg(msg: KernelMessage.ICommMsgMsg): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Send an `comm_close` message.
|
|
93
|
+
*
|
|
94
|
+
* @param close - The comm_close message.
|
|
95
|
+
*/
|
|
96
|
+
commClose(msg: KernelMessage.ICommCloseMsg): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Send an `input_reply` message.
|
|
99
|
+
*
|
|
100
|
+
* @param content - The content of the reply.
|
|
101
|
+
*/
|
|
102
|
+
inputReply(content: KernelMessage.IInputReplyMsg['content']): Promise<void>;
|
|
103
|
+
private _worker;
|
|
104
|
+
private _remoteKernel;
|
|
105
|
+
private _ready;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A namespace for PyodideKernel statics.
|
|
109
|
+
*/
|
|
110
|
+
export declare namespace PyodideKernel {
|
|
111
|
+
/**
|
|
112
|
+
* The instantiation options for a Pyodide kernel
|
|
113
|
+
*/
|
|
114
|
+
interface IOptions extends IKernel.IOptions {
|
|
115
|
+
/**
|
|
116
|
+
* The URL to fetch Pyodide.
|
|
117
|
+
*/
|
|
118
|
+
pyodideUrl: string;
|
|
119
|
+
/**
|
|
120
|
+
* The URLs from which to attempt PyPI API requests
|
|
121
|
+
*/
|
|
122
|
+
pipliteUrls: string[];
|
|
123
|
+
/**
|
|
124
|
+
* Do not try pypi.org if `piplite.install` fails against local URLs
|
|
125
|
+
*/
|
|
126
|
+
disablePyPIFallback: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Whether or not to mount the Emscripten drive
|
|
129
|
+
*/
|
|
130
|
+
mountDrive: boolean;
|
|
131
|
+
}
|
|
132
|
+
}
|
package/lib/kernel.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { PromiseDelegate } from '@lumino/coreutils';
|
|
2
|
+
import { PageConfig } from '@jupyterlab/coreutils';
|
|
3
|
+
import { BaseKernel } from '@jupyterlite/kernel';
|
|
4
|
+
import { wrap } from 'comlink';
|
|
5
|
+
import { allJSONUrl, pipliteWheelUrl } from './_pypi';
|
|
6
|
+
/**
|
|
7
|
+
* A kernel that executes Python code with Pyodide.
|
|
8
|
+
*/
|
|
9
|
+
export class PyodideKernel extends BaseKernel {
|
|
10
|
+
/**
|
|
11
|
+
* Instantiate a new PyodideKernel
|
|
12
|
+
*
|
|
13
|
+
* @param options The instantiation options for a new PyodideKernel
|
|
14
|
+
*/
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super(options);
|
|
17
|
+
this._ready = new PromiseDelegate();
|
|
18
|
+
this._worker = this.initWorker(options);
|
|
19
|
+
this._worker.onmessage = (e) => this._processWorkerMessage(e.data);
|
|
20
|
+
this._remoteKernel = wrap(this._worker);
|
|
21
|
+
this.initRemote(options);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Load the worker.
|
|
25
|
+
*
|
|
26
|
+
* ### Note
|
|
27
|
+
*
|
|
28
|
+
* Subclasses must implement this typographically almost _exactly_ for
|
|
29
|
+
* webpack to find it.
|
|
30
|
+
*/
|
|
31
|
+
initWorker(options) {
|
|
32
|
+
return new Worker(new URL('./comlink.worker.js', import.meta.url), {
|
|
33
|
+
type: 'module',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async initRemote(options) {
|
|
37
|
+
const remoteOptions = this.initRemoteOptions(options);
|
|
38
|
+
await this._remoteKernel.initialize(remoteOptions);
|
|
39
|
+
this._ready.resolve();
|
|
40
|
+
}
|
|
41
|
+
initRemoteOptions(options) {
|
|
42
|
+
const { pyodideUrl } = options;
|
|
43
|
+
const indexUrl = pyodideUrl.slice(0, pyodideUrl.lastIndexOf('/') + 1);
|
|
44
|
+
const baseUrl = PageConfig.getBaseUrl();
|
|
45
|
+
const pipliteUrls = [...(options.pipliteUrls || []), allJSONUrl.default];
|
|
46
|
+
const disablePyPIFallback = !!options.disablePyPIFallback;
|
|
47
|
+
return {
|
|
48
|
+
baseUrl,
|
|
49
|
+
pyodideUrl,
|
|
50
|
+
indexUrl,
|
|
51
|
+
pipliteWheelUrl: pipliteWheelUrl.default,
|
|
52
|
+
pipliteUrls,
|
|
53
|
+
disablePyPIFallback,
|
|
54
|
+
location: this.location,
|
|
55
|
+
mountDrive: options.mountDrive,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Dispose the kernel.
|
|
60
|
+
*/
|
|
61
|
+
dispose() {
|
|
62
|
+
if (this.isDisposed) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this._worker.terminate();
|
|
66
|
+
this._worker = null;
|
|
67
|
+
super.dispose();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A promise that is fulfilled when the kernel is ready.
|
|
71
|
+
*/
|
|
72
|
+
get ready() {
|
|
73
|
+
return this._ready.promise;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Process a message coming from the pyodide web worker.
|
|
77
|
+
*
|
|
78
|
+
* @param msg The worker message to process.
|
|
79
|
+
*/
|
|
80
|
+
_processWorkerMessage(msg) {
|
|
81
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
82
|
+
if (!msg.type) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
switch (msg.type) {
|
|
86
|
+
case 'stream': {
|
|
87
|
+
const bundle = (_a = msg.bundle) !== null && _a !== void 0 ? _a : { name: 'stdout', text: '' };
|
|
88
|
+
this.stream(bundle, msg.parentHeader);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'input_request': {
|
|
92
|
+
const bundle = (_b = msg.content) !== null && _b !== void 0 ? _b : { prompt: '', password: false };
|
|
93
|
+
this.inputRequest(bundle, msg.parentHeader);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'display_data': {
|
|
97
|
+
const bundle = (_c = msg.bundle) !== null && _c !== void 0 ? _c : { data: {}, metadata: {}, transient: {} };
|
|
98
|
+
this.displayData(bundle, msg.parentHeader);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'update_display_data': {
|
|
102
|
+
const bundle = (_d = msg.bundle) !== null && _d !== void 0 ? _d : { data: {}, metadata: {}, transient: {} };
|
|
103
|
+
this.updateDisplayData(bundle, msg.parentHeader);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'clear_output': {
|
|
107
|
+
const bundle = (_e = msg.bundle) !== null && _e !== void 0 ? _e : { wait: false };
|
|
108
|
+
this.clearOutput(bundle, msg.parentHeader);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'execute_result': {
|
|
112
|
+
const bundle = (_f = msg.bundle) !== null && _f !== void 0 ? _f : {
|
|
113
|
+
execution_count: 0,
|
|
114
|
+
data: {},
|
|
115
|
+
metadata: {},
|
|
116
|
+
};
|
|
117
|
+
this.publishExecuteResult(bundle, msg.parentHeader);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case 'execute_error': {
|
|
121
|
+
const bundle = (_g = msg.bundle) !== null && _g !== void 0 ? _g : { ename: '', evalue: '', traceback: [] };
|
|
122
|
+
this.publishExecuteError(bundle, msg.parentHeader);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'comm_msg':
|
|
126
|
+
case 'comm_open':
|
|
127
|
+
case 'comm_close': {
|
|
128
|
+
this.handleComm(msg.type, msg.content, msg.metadata, msg.buffers, msg.parentHeader);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Handle a kernel_info_request message
|
|
135
|
+
*/
|
|
136
|
+
async kernelInfoRequest() {
|
|
137
|
+
const content = {
|
|
138
|
+
implementation: 'pyodide',
|
|
139
|
+
implementation_version: '0.1.0',
|
|
140
|
+
language_info: {
|
|
141
|
+
codemirror_mode: {
|
|
142
|
+
name: 'python',
|
|
143
|
+
version: 3,
|
|
144
|
+
},
|
|
145
|
+
file_extension: '.py',
|
|
146
|
+
mimetype: 'text/x-python',
|
|
147
|
+
name: 'python',
|
|
148
|
+
nbconvert_exporter: 'python',
|
|
149
|
+
pygments_lexer: 'ipython3',
|
|
150
|
+
version: '3.8',
|
|
151
|
+
},
|
|
152
|
+
protocol_version: '5.3',
|
|
153
|
+
status: 'ok',
|
|
154
|
+
banner: 'A WebAssembly-powered Python kernel backed by Pyodide',
|
|
155
|
+
help_links: [
|
|
156
|
+
{
|
|
157
|
+
text: 'Python (WASM) Kernel',
|
|
158
|
+
url: 'https://pyodide.org',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
return content;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Handle an `execute_request` message
|
|
166
|
+
*
|
|
167
|
+
* @param msg The parent message.
|
|
168
|
+
*/
|
|
169
|
+
async executeRequest(content) {
|
|
170
|
+
await this.ready;
|
|
171
|
+
const result = await this._remoteKernel.execute(content, this.parent);
|
|
172
|
+
result.execution_count = this.executionCount;
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Handle an complete_request message
|
|
177
|
+
*
|
|
178
|
+
* @param msg The parent message.
|
|
179
|
+
*/
|
|
180
|
+
async completeRequest(content) {
|
|
181
|
+
return await this._remoteKernel.complete(content, this.parent);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Handle an `inspect_request` message.
|
|
185
|
+
*
|
|
186
|
+
* @param content - The content of the request.
|
|
187
|
+
*
|
|
188
|
+
* @returns A promise that resolves with the response message.
|
|
189
|
+
*/
|
|
190
|
+
async inspectRequest(content) {
|
|
191
|
+
return await this._remoteKernel.inspect(content, this.parent);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Handle an `is_complete_request` message.
|
|
195
|
+
*
|
|
196
|
+
* @param content - The content of the request.
|
|
197
|
+
*
|
|
198
|
+
* @returns A promise that resolves with the response message.
|
|
199
|
+
*/
|
|
200
|
+
async isCompleteRequest(content) {
|
|
201
|
+
return await this._remoteKernel.isComplete(content, this.parent);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Handle a `comm_info_request` message.
|
|
205
|
+
*
|
|
206
|
+
* @param content - The content of the request.
|
|
207
|
+
*
|
|
208
|
+
* @returns A promise that resolves with the response message.
|
|
209
|
+
*/
|
|
210
|
+
async commInfoRequest(content) {
|
|
211
|
+
return await this._remoteKernel.commInfo(content, this.parent);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Send an `comm_open` message.
|
|
215
|
+
*
|
|
216
|
+
* @param msg - The comm_open message.
|
|
217
|
+
*/
|
|
218
|
+
async commOpen(msg) {
|
|
219
|
+
return await this._remoteKernel.commOpen(msg, this.parent);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Send an `comm_msg` message.
|
|
223
|
+
*
|
|
224
|
+
* @param msg - The comm_msg message.
|
|
225
|
+
*/
|
|
226
|
+
async commMsg(msg) {
|
|
227
|
+
return await this._remoteKernel.commMsg(msg, this.parent);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Send an `comm_close` message.
|
|
231
|
+
*
|
|
232
|
+
* @param close - The comm_close message.
|
|
233
|
+
*/
|
|
234
|
+
async commClose(msg) {
|
|
235
|
+
return await this._remoteKernel.commClose(msg, this.parent);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Send an `input_reply` message.
|
|
239
|
+
*
|
|
240
|
+
* @param content - The content of the reply.
|
|
241
|
+
*/
|
|
242
|
+
async inputReply(content) {
|
|
243
|
+
return await this._remoteKernel.inputReply(content, this.parent);
|
|
244
|
+
}
|
|
245
|
+
}
|
package/lib/tokens.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Definitions for the Pyodide kernel.
|
|
3
|
+
*/
|
|
4
|
+
import type { Remote } from 'comlink';
|
|
5
|
+
import { IWorkerKernel } from '@jupyterlite/kernel';
|
|
6
|
+
/**
|
|
7
|
+
* An interface for Pyodide workers.
|
|
8
|
+
*/
|
|
9
|
+
export interface IPyodideWorkerKernel extends IWorkerKernel {
|
|
10
|
+
/**
|
|
11
|
+
* Handle any lazy initialization activities.
|
|
12
|
+
*/
|
|
13
|
+
initialize(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An convenience interface for Pyodide workers wrapped by a comlink Remote.
|
|
17
|
+
*/
|
|
18
|
+
export type IRemotePyodideWorkerKernel = Remote<IPyodideWorkerKernel>;
|
|
19
|
+
/**
|
|
20
|
+
* An namespace for Pyodide workers.
|
|
21
|
+
*/
|
|
22
|
+
export declare namespace IPyodideWorkerKernel {
|
|
23
|
+
/**
|
|
24
|
+
* Initialization options for a worker.
|
|
25
|
+
*/
|
|
26
|
+
interface IOptions extends IWorkerKernel.IOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The URL of the main `pyodide.js` file in the standard pyodide layout.
|
|
29
|
+
*/
|
|
30
|
+
pyodideUrl: string;
|
|
31
|
+
/**
|
|
32
|
+
* The URL of a pyodide index file in the standard pyodide layout.
|
|
33
|
+
*/
|
|
34
|
+
indexUrl: string;
|
|
35
|
+
/**
|
|
36
|
+
* The URL of the `piplite` wheel for bootstrapping.
|
|
37
|
+
*/
|
|
38
|
+
pipliteWheelUrl: string;
|
|
39
|
+
/**
|
|
40
|
+
* The URLs of additional warehouse-like wheel listings.
|
|
41
|
+
*/
|
|
42
|
+
pipliteUrls: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Whether `piplite` should fall back to the hard-coded `pypi.org` for resolving packages.
|
|
45
|
+
*/
|
|
46
|
+
disablePyPIFallback: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The current working directory in which to start the kernel.
|
|
49
|
+
*/
|
|
50
|
+
location: string;
|
|
51
|
+
/**
|
|
52
|
+
* Whether or not to mount the Emscripten drive
|
|
53
|
+
*/
|
|
54
|
+
mountDrive: boolean;
|
|
55
|
+
}
|
|
56
|
+
}
|
package/lib/tokens.js
ADDED
package/lib/worker.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type Pyodide from 'pyodide';
|
|
2
|
+
import type { DriveFS } from '@jupyterlite/contents';
|
|
3
|
+
import type { IPyodideWorkerKernel } from './tokens';
|
|
4
|
+
export declare class PyodideRemoteKernel {
|
|
5
|
+
constructor();
|
|
6
|
+
/**
|
|
7
|
+
* Accept the URLs from the host
|
|
8
|
+
**/
|
|
9
|
+
initialize(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
10
|
+
protected initRuntime(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
11
|
+
protected initPackageManager(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
12
|
+
protected initKernel(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
13
|
+
protected initGlobals(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Setup custom Emscripten FileSystem
|
|
16
|
+
*/
|
|
17
|
+
protected initFilesystem(options: IPyodideWorkerKernel.IOptions): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Recursively convert a Map to a JavaScript object
|
|
20
|
+
* @param obj A Map, Array, or other object to convert
|
|
21
|
+
*/
|
|
22
|
+
mapToObject(obj: any): any;
|
|
23
|
+
/**
|
|
24
|
+
* Format the response from the Pyodide evaluation.
|
|
25
|
+
*
|
|
26
|
+
* @param res The result object from the Pyodide evaluation
|
|
27
|
+
*/
|
|
28
|
+
formatResult(res: any): any;
|
|
29
|
+
/**
|
|
30
|
+
* Makes sure pyodide is ready before continuing, and cache the parent message.
|
|
31
|
+
*/
|
|
32
|
+
setup(parent: any): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Execute code with the interpreter.
|
|
35
|
+
*
|
|
36
|
+
* @param content The incoming message with the code to execute.
|
|
37
|
+
*/
|
|
38
|
+
execute(content: any, parent: any): Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Complete the code submitted by a user.
|
|
41
|
+
*
|
|
42
|
+
* @param content The incoming message with the code to complete.
|
|
43
|
+
*/
|
|
44
|
+
complete(content: any, parent: any): Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Inspect the code submitted by a user.
|
|
47
|
+
*
|
|
48
|
+
* @param content The incoming message with the code to inspect.
|
|
49
|
+
*/
|
|
50
|
+
inspect(content: {
|
|
51
|
+
code: string;
|
|
52
|
+
cursor_pos: number;
|
|
53
|
+
detail_level: 0 | 1;
|
|
54
|
+
}, parent: any): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Check code for completeness submitted by a user.
|
|
57
|
+
*
|
|
58
|
+
* @param content The incoming message with the code to check.
|
|
59
|
+
*/
|
|
60
|
+
isComplete(content: {
|
|
61
|
+
code: string;
|
|
62
|
+
}, parent: any): Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Respond to the commInfoRequest.
|
|
65
|
+
*
|
|
66
|
+
* @param content The incoming message with the comm target name.
|
|
67
|
+
*/
|
|
68
|
+
commInfo(content: any, parent: any): Promise<{
|
|
69
|
+
comms: any;
|
|
70
|
+
status: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Respond to the commOpen.
|
|
74
|
+
*
|
|
75
|
+
* @param content The incoming message with the comm open.
|
|
76
|
+
*/
|
|
77
|
+
commOpen(content: any, parent: any): Promise<any>;
|
|
78
|
+
/**
|
|
79
|
+
* Respond to the commMsg.
|
|
80
|
+
*
|
|
81
|
+
* @param content The incoming message with the comm msg.
|
|
82
|
+
*/
|
|
83
|
+
commMsg(content: any, parent: any): Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Respond to the commClose.
|
|
86
|
+
*
|
|
87
|
+
* @param content The incoming message with the comm close.
|
|
88
|
+
*/
|
|
89
|
+
commClose(content: any, parent: any): Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Resolve the input request by getting back the reply from the main thread
|
|
92
|
+
*
|
|
93
|
+
* @param content The incoming message with the reply
|
|
94
|
+
*/
|
|
95
|
+
inputReply(content: any, parent: any): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Send a input request to the front-end.
|
|
98
|
+
*
|
|
99
|
+
* @param prompt the text to show at the prompt
|
|
100
|
+
* @param password Is the request for a password?
|
|
101
|
+
*/
|
|
102
|
+
sendInputRequest(prompt: string, password: boolean): Promise<void>;
|
|
103
|
+
getpass(prompt: string): Promise<any>;
|
|
104
|
+
input(prompt: string): Promise<any>;
|
|
105
|
+
/**
|
|
106
|
+
* Send a comm message to the front-end.
|
|
107
|
+
*
|
|
108
|
+
* @param type The type of the comm message.
|
|
109
|
+
* @param content The content.
|
|
110
|
+
* @param metadata The metadata.
|
|
111
|
+
* @param ident The ident.
|
|
112
|
+
* @param buffers The binary buffers.
|
|
113
|
+
*/
|
|
114
|
+
sendComm(type: string, content: any, metadata: any, ident: any, buffers: any): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Initialization options.
|
|
117
|
+
*/
|
|
118
|
+
protected _options: IPyodideWorkerKernel.IOptions | null;
|
|
119
|
+
/**
|
|
120
|
+
* A promise that resolves when all initiaization is complete.
|
|
121
|
+
*/
|
|
122
|
+
protected _initialized: Promise<void>;
|
|
123
|
+
private _initializer;
|
|
124
|
+
protected _pyodide: Pyodide.PyodideInterface;
|
|
125
|
+
/** TODO: real typing */
|
|
126
|
+
protected _localPath: string;
|
|
127
|
+
protected _driveName: string;
|
|
128
|
+
protected _kernel: any;
|
|
129
|
+
protected _interpreter: any;
|
|
130
|
+
protected _stdout_stream: any;
|
|
131
|
+
protected _stderr_stream: any;
|
|
132
|
+
protected _resolveInputReply: any;
|
|
133
|
+
protected _driveFS: DriveFS | null;
|
|
134
|
+
}
|