@jupyterlite/pyodide-kernel 0.4.0-beta.0 → 0.4.0-rc.0

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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './_pypi';
2
2
  export * from './coincident.worker';
3
+ export * from './comlink.worker';
3
4
  export * from './kernel';
4
5
  export * from './tokens';
5
6
  export * from './worker';
package/lib/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
  export * from './_pypi';
4
4
  export * from './coincident.worker';
5
+ export * from './comlink.worker';
5
6
  export * from './kernel';
6
7
  export * from './tokens';
7
8
  export * from './worker';
package/lib/kernel.d.ts CHANGED
@@ -11,7 +11,6 @@ export declare class PyodideKernel extends BaseKernel implements IKernel {
11
11
  * @param options The instantiation options for a new PyodideKernel
12
12
  */
13
13
  constructor(options: PyodideKernel.IOptions);
14
- private setupFilesystemAPIs;
15
14
  /**
16
15
  * Load the worker.
17
16
  *
@@ -21,6 +20,13 @@ export declare class PyodideKernel extends BaseKernel implements IKernel {
21
20
  * webpack to find it.
22
21
  */
23
22
  protected initWorker(options: PyodideKernel.IOptions): Worker;
23
+ /**
24
+ * Initialize the remote kernel.
25
+ * Use coincident if crossOriginIsolated, comlink otherwise
26
+ * See the two following issues for more context:
27
+ * - https://github.com/jupyterlite/jupyterlite/issues/1424
28
+ * - https://github.com/jupyterlite/pyodide-kernel/pull/126
29
+ */
24
30
  protected initRemote(options: PyodideKernel.IOptions): IPyodideWorkerKernel;
25
31
  protected initRemoteOptions(options: PyodideKernel.IOptions): IPyodideWorkerKernel.IOptions;
26
32
  /**
package/lib/kernel.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import coincident from 'coincident';
2
+ import { proxy, wrap } from 'comlink';
2
3
  import { PromiseDelegate } from '@lumino/coreutils';
3
4
  import { PageConfig } from '@jupyterlab/coreutils';
4
5
  import { BaseKernel } from '@jupyterlite/kernel';
@@ -17,23 +18,8 @@ export class PyodideKernel extends BaseKernel {
17
18
  super(options);
18
19
  this._ready = new PromiseDelegate();
19
20
  this._worker = this.initWorker(options);
20
- this._worker.onmessage = (e) => this._processWorkerMessage(e.data);
21
21
  this._remoteKernel = this.initRemote(options);
22
22
  this._contentsManager = options.contentsManager;
23
- this.setupFilesystemAPIs();
24
- }
25
- setupFilesystemAPIs() {
26
- this._remoteKernel.processDriveRequest = async (data) => {
27
- if (!DriveContentsProcessor) {
28
- throw new Error('File system calls over Atomics.wait is only supported with jupyterlite>=0.4.0a3');
29
- }
30
- if (this._contentsProcessor === undefined) {
31
- this._contentsProcessor = new DriveContentsProcessor({
32
- contentsManager: this._contentsManager,
33
- });
34
- }
35
- return await this._contentsProcessor.processDriveRequest(data);
36
- };
37
23
  }
38
24
  /**
39
25
  * Load the worker.
@@ -44,12 +30,46 @@ export class PyodideKernel extends BaseKernel {
44
30
  * webpack to find it.
45
31
  */
46
32
  initWorker(options) {
47
- return new Worker(new URL('./coincident.worker.js', import.meta.url), {
48
- type: 'module',
49
- });
33
+ if (crossOriginIsolated) {
34
+ return new Worker(new URL('./coincident.worker.js', import.meta.url), {
35
+ type: 'module',
36
+ });
37
+ }
38
+ else {
39
+ return new Worker(new URL('./comlink.worker.js', import.meta.url), {
40
+ type: 'module',
41
+ });
42
+ }
50
43
  }
44
+ /**
45
+ * Initialize the remote kernel.
46
+ * Use coincident if crossOriginIsolated, comlink otherwise
47
+ * See the two following issues for more context:
48
+ * - https://github.com/jupyterlite/jupyterlite/issues/1424
49
+ * - https://github.com/jupyterlite/pyodide-kernel/pull/126
50
+ */
51
51
  initRemote(options) {
52
- const remote = coincident(this._worker);
52
+ let remote;
53
+ if (crossOriginIsolated) {
54
+ remote = coincident(this._worker);
55
+ remote.processWorkerMessage = this._processWorkerMessage.bind(this);
56
+ // The coincident worker uses its own filesystem API:
57
+ remote.processDriveRequest = async (data) => {
58
+ if (!DriveContentsProcessor) {
59
+ throw new Error('File system calls over Atomics.wait is only supported with jupyterlite>=0.4.0a3');
60
+ }
61
+ if (this._contentsProcessor === undefined) {
62
+ this._contentsProcessor = new DriveContentsProcessor({
63
+ contentsManager: this._contentsManager,
64
+ });
65
+ }
66
+ return await this._contentsProcessor.processDriveRequest(data);
67
+ };
68
+ }
69
+ else {
70
+ remote = wrap(this._worker);
71
+ remote.registerCallback(proxy(this._processWorkerMessage.bind(this)));
72
+ }
53
73
  const remoteOptions = this.initRemoteOptions(options);
54
74
  remote.initialize(remoteOptions).then(this._ready.resolve.bind(this._ready));
55
75
  return remote;
package/lib/tokens.d.ts CHANGED
@@ -20,6 +20,15 @@ export interface IPyodideWorkerKernel extends IWorkerKernel {
20
20
  * @param data
21
21
  */
22
22
  processDriveRequest<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;
23
+ /**
24
+ * Process worker message
25
+ * @param msg
26
+ */
27
+ processWorkerMessage(msg: any): void;
28
+ /**
29
+ * Register a callback for handling messages from the worker.
30
+ */
31
+ registerCallback(callback: (msg: any) => void): void;
23
32
  }
24
33
  /**
25
34
  * Deprecated.
package/lib/worker.d.ts CHANGED
@@ -27,6 +27,11 @@ export declare class PyodideRemoteKernel {
27
27
  * @param res The result object from the Pyodide evaluation
28
28
  */
29
29
  formatResult(res: any): any;
30
+ /**
31
+ * Register the callback function to send messages from the worker back to the main thread.
32
+ * @param callback the callback to register
33
+ */
34
+ registerCallback(callback: (msg: any) => void): void;
30
35
  /**
31
36
  * Makes sure pyodide is ready before continuing, and cache the parent message.
32
37
  */
@@ -129,4 +134,5 @@ export declare class PyodideRemoteKernel {
129
134
  protected _stderr_stream: any;
130
135
  protected _resolveInputReply: any;
131
136
  protected _driveFS: DriveFS | null;
137
+ protected _sendWorkerMessage: (msg: any) => void;
132
138
  }
package/lib/worker.js CHANGED
@@ -12,6 +12,7 @@ export class PyodideRemoteKernel {
12
12
  this._localPath = '';
13
13
  this._driveName = '';
14
14
  this._driveFS = null;
15
+ this._sendWorkerMessage = () => { };
15
16
  this._initialized = new Promise((resolve, reject) => {
16
17
  this._initializer = { resolve, reject };
17
18
  });
@@ -156,6 +157,13 @@ export class PyodideRemoteKernel {
156
157
  const results = this.mapToObject(m);
157
158
  return results;
158
159
  }
160
+ /**
161
+ * Register the callback function to send messages from the worker back to the main thread.
162
+ * @param callback the callback to register
163
+ */
164
+ registerCallback(callback) {
165
+ this._sendWorkerMessage = callback;
166
+ }
159
167
  /**
160
168
  * Makes sure pyodide is ready before continuing, and cache the parent message.
161
169
  */
@@ -176,7 +184,7 @@ export class PyodideRemoteKernel {
176
184
  data: this.formatResult(data),
177
185
  metadata: this.formatResult(metadata),
178
186
  };
179
- postMessage({
187
+ this._sendWorkerMessage({
180
188
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
181
189
  bundle,
182
190
  type: 'execute_result',
@@ -188,7 +196,7 @@ export class PyodideRemoteKernel {
188
196
  evalue: evalue,
189
197
  traceback: traceback,
190
198
  };
191
- postMessage({
199
+ this._sendWorkerMessage({
192
200
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
193
201
  bundle,
194
202
  type: 'execute_error',
@@ -198,7 +206,7 @@ export class PyodideRemoteKernel {
198
206
  const bundle = {
199
207
  wait: this.formatResult(wait),
200
208
  };
201
- postMessage({
209
+ this._sendWorkerMessage({
202
210
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
203
211
  bundle,
204
212
  type: 'clear_output',
@@ -210,7 +218,7 @@ export class PyodideRemoteKernel {
210
218
  metadata: this.formatResult(metadata),
211
219
  transient: this.formatResult(transient),
212
220
  };
213
- postMessage({
221
+ this._sendWorkerMessage({
214
222
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
215
223
  bundle,
216
224
  type: 'display_data',
@@ -222,7 +230,7 @@ export class PyodideRemoteKernel {
222
230
  metadata: this.formatResult(metadata),
223
231
  transient: this.formatResult(transient),
224
232
  };
225
- postMessage({
233
+ this._sendWorkerMessage({
226
234
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
227
235
  bundle,
228
236
  type: 'update_display_data',
@@ -233,7 +241,7 @@ export class PyodideRemoteKernel {
233
241
  name: this.formatResult(name),
234
242
  text: this.formatResult(text),
235
243
  };
236
- postMessage({
244
+ this._sendWorkerMessage({
237
245
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
238
246
  bundle,
239
247
  type: 'stream',
@@ -355,7 +363,7 @@ export class PyodideRemoteKernel {
355
363
  prompt,
356
364
  password,
357
365
  };
358
- postMessage({
366
+ this._sendWorkerMessage({
359
367
  type: 'input_request',
360
368
  parentHeader: this.formatResult(this._kernel._parent_header)['header'],
361
369
  content,
@@ -389,7 +397,7 @@ export class PyodideRemoteKernel {
389
397
  * @param buffers The binary buffers.
390
398
  */
391
399
  async sendComm(type, content, metadata, ident, buffers) {
392
- postMessage({
400
+ this._sendWorkerMessage({
393
401
  type: type,
394
402
  content: this.formatResult(content),
395
403
  metadata: this.formatResult(metadata),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/pyodide-kernel",
3
- "version": "0.4.0-beta.0",
3
+ "version": "0.4.0-rc.0",
4
4
  "description": "JupyterLite - Pyodide Kernel",
5
5
  "homepage": "https://github.com/jupyterlite/pyodide-kernel",
6
6
  "bugs": {
@@ -33,11 +33,13 @@
33
33
  "schema/*.json"
34
34
  ],
35
35
  "scripts": {
36
- "build": "jlpm build:lib && jlpm build:worker",
36
+ "build": "jlpm build:lib && jlpm build:workers",
37
37
  "build:lib": "tsc -b",
38
38
  "build:prod": "jlpm build",
39
39
  "build:py": "python scripts/generate-wheels-js.py",
40
- "build:worker": "esbuild --bundle --minify --sourcemap --target=es2019 --format=esm --outfile=lib/coincident.worker.js src/coincident.worker.ts",
40
+ "build:coincident:worker": "esbuild --bundle --minify --sourcemap --target=es2019 --format=esm --outfile=lib/coincident.worker.js src/coincident.worker.ts",
41
+ "build:comlink:worker": "esbuild --bundle --minify --sourcemap --target=es2019 --format=esm --outfile=lib/comlink.worker.js src/comlink.worker.ts",
42
+ "build:workers": "jlpm build:coincident:worker && jlpm build:comlink:worker",
41
43
  "dist": "cd ../../dist && npm pack ../packages/pyodide-kernel",
42
44
  "clean": "jlpm clean:lib && jlpm clean:py",
43
45
  "clean:all": "jlpm clean",
@@ -55,7 +57,8 @@
55
57
  "@jupyterlab/coreutils": "^6.1.1",
56
58
  "@jupyterlite/contents": "^0.4.0-alpha.3",
57
59
  "@jupyterlite/kernel": "^0.4.0-alpha.3",
58
- "coincident": "^1.2.3"
60
+ "coincident": "^1.2.3",
61
+ "comlink": "^4.4.1"
59
62
  },
60
63
  "devDependencies": {
61
64
  "@babel/core": "^7.22.17",
@@ -73,8 +76,8 @@
73
76
  },
74
77
  "pyodide-kernel": {
75
78
  "packages": {
76
- "py/pyodide-kernel": "0.4.0b0",
77
- "py/piplite": "0.4.0b0",
79
+ "py/pyodide-kernel": "0.4.0rc0",
80
+ "py/piplite": "0.4.0rc0",
78
81
  "py/ipykernel": "6.9.2",
79
82
  "py/widgetsnbextension3/widgetsnbextension": "3.6.6",
80
83
  "py/widgetsnbextension4/widgetsnbextension": "4.0.11"
package/pypi/all.json CHANGED
@@ -5,19 +5,19 @@
5
5
  {
6
6
  "comment_text": "",
7
7
  "digests": {
8
- "md5": "f6eeab1d135fe243aa8478496d0db887",
9
- "sha256": "cfa1226a5f704a81946a6e2ab21f083d89beebac8b490c3597d11b2967c0219f"
8
+ "md5": "bfcf0f23a0e14dd8ca4720a4d39102df",
9
+ "sha256": "3613e768c946098dbd03df89133986ea5cd05207253172037da261c565dfd8f9"
10
10
  },
11
11
  "downloads": -1,
12
12
  "filename": "ipykernel-6.9.2-py3-none-any.whl",
13
13
  "has_sig": false,
14
- "md5_digest": "f6eeab1d135fe243aa8478496d0db887",
14
+ "md5_digest": "bfcf0f23a0e14dd8ca4720a4d39102df",
15
15
  "packagetype": "bdist_wheel",
16
16
  "python_version": "py3",
17
17
  "requires_python": ">=3.10",
18
- "size": 2732,
19
- "upload_time": "2024-06-21T07:29:44.671026Z",
20
- "upload_time_iso_8601": "2024-06-21T07:29:44.671026Z",
18
+ "size": 2731,
19
+ "upload_time": "2024-07-23T12:47:35.825642Z",
20
+ "upload_time_iso_8601": "2024-07-23T12:47:35.825642Z",
21
21
  "url": "./ipykernel-6.9.2-py3-none-any.whl",
22
22
  "yanked": false,
23
23
  "yanked_reason": null
@@ -27,24 +27,24 @@
27
27
  },
28
28
  "piplite": {
29
29
  "releases": {
30
- "0.4.0b0": [
30
+ "0.4.0rc0": [
31
31
  {
32
32
  "comment_text": "",
33
33
  "digests": {
34
- "md5": "c78319f10cca7dcc6503ac29739c90fa",
35
- "sha256": "63c6b2264b50f922d13d350b100c95b060a268b3788e03519151f8a0721cad18"
34
+ "md5": "3c599c26efa4cc572ff31e040d85cc47",
35
+ "sha256": "381ba5af85562cf6ea8dda455e9a680057219d12f50dbde1157f24af53031e7e"
36
36
  },
37
37
  "downloads": -1,
38
- "filename": "piplite-0.4.0b0-py3-none-any.whl",
38
+ "filename": "piplite-0.4.0rc0-py3-none-any.whl",
39
39
  "has_sig": false,
40
- "md5_digest": "c78319f10cca7dcc6503ac29739c90fa",
40
+ "md5_digest": "3c599c26efa4cc572ff31e040d85cc47",
41
41
  "packagetype": "bdist_wheel",
42
42
  "python_version": "py3",
43
43
  "requires_python": "<3.12,>=3.11",
44
- "size": 7191,
45
- "upload_time": "2024-06-21T07:29:44.671026Z",
46
- "upload_time_iso_8601": "2024-06-21T07:29:44.671026Z",
47
- "url": "./piplite-0.4.0b0-py3-none-any.whl",
44
+ "size": 7197,
45
+ "upload_time": "2024-07-23T12:47:35.825642Z",
46
+ "upload_time_iso_8601": "2024-07-23T12:47:35.825642Z",
47
+ "url": "./piplite-0.4.0rc0-py3-none-any.whl",
48
48
  "yanked": false,
49
49
  "yanked_reason": null
50
50
  }
@@ -53,24 +53,24 @@
53
53
  },
54
54
  "pyodide-kernel": {
55
55
  "releases": {
56
- "0.4.0b0": [
56
+ "0.4.0rc0": [
57
57
  {
58
58
  "comment_text": "",
59
59
  "digests": {
60
- "md5": "8bed3319e15ebcc50bfe6aba721a248e",
61
- "sha256": "7b3826ae4b4382124ee8fd0bd7a54fb8af4fd8607baff80642a089921eaec89b"
60
+ "md5": "faeb45da191213baf8500cf640bc5ee8",
61
+ "sha256": "9ddc114be90b8ab24f7557cfec0e894640a417aa9d5a1a23b2f3d9952e474234"
62
62
  },
63
63
  "downloads": -1,
64
- "filename": "pyodide_kernel-0.4.0b0-py3-none-any.whl",
64
+ "filename": "pyodide_kernel-0.4.0rc0-py3-none-any.whl",
65
65
  "has_sig": false,
66
- "md5_digest": "8bed3319e15ebcc50bfe6aba721a248e",
66
+ "md5_digest": "faeb45da191213baf8500cf640bc5ee8",
67
67
  "packagetype": "bdist_wheel",
68
68
  "python_version": "py3",
69
69
  "requires_python": "<3.12,>=3.11",
70
- "size": 11029,
71
- "upload_time": "2024-06-21T07:29:44.671026Z",
72
- "upload_time_iso_8601": "2024-06-21T07:29:44.671026Z",
73
- "url": "./pyodide_kernel-0.4.0b0-py3-none-any.whl",
70
+ "size": 11038,
71
+ "upload_time": "2024-07-23T12:47:35.825642Z",
72
+ "upload_time_iso_8601": "2024-07-23T12:47:35.825642Z",
73
+ "url": "./pyodide_kernel-0.4.0rc0-py3-none-any.whl",
74
74
  "yanked": false,
75
75
  "yanked_reason": null
76
76
  }
@@ -83,19 +83,19 @@
83
83
  {
84
84
  "comment_text": "",
85
85
  "digests": {
86
- "md5": "8734350ca544b00d7a9eb06ce178367f",
87
- "sha256": "c7486289ed7bcb7bdbaf02e99f6cb55ce8a3e9feef7d801463caad8f4b701446"
86
+ "md5": "9dfde1dae175b724fc32efed1deb475d",
87
+ "sha256": "eb560faf742c2fe3b48a14d356f78809e086185c6e8bf48674524219cbfc52f3"
88
88
  },
89
89
  "downloads": -1,
90
90
  "filename": "widgetsnbextension-3.6.6-py3-none-any.whl",
91
91
  "has_sig": false,
92
- "md5_digest": "8734350ca544b00d7a9eb06ce178367f",
92
+ "md5_digest": "9dfde1dae175b724fc32efed1deb475d",
93
93
  "packagetype": "bdist_wheel",
94
94
  "python_version": "py3",
95
95
  "requires_python": "<3.12,>=3.11",
96
- "size": 2348,
97
- "upload_time": "2024-06-21T07:29:44.671026Z",
98
- "upload_time_iso_8601": "2024-06-21T07:29:44.671026Z",
96
+ "size": 2347,
97
+ "upload_time": "2024-07-23T12:47:35.829642Z",
98
+ "upload_time_iso_8601": "2024-07-23T12:47:35.829642Z",
99
99
  "url": "./widgetsnbextension-3.6.6-py3-none-any.whl",
100
100
  "yanked": false,
101
101
  "yanked_reason": null
@@ -105,19 +105,19 @@
105
105
  {
106
106
  "comment_text": "",
107
107
  "digests": {
108
- "md5": "7c782a5f84d0a85cf707be540b5c86ac",
109
- "sha256": "670ed260a7c7f29c067e2d7d89e135a2ccd824ad217e0b4b18c9159b3ef073e2"
108
+ "md5": "e75f3f8c90eaf5ab63c79b2b22236395",
109
+ "sha256": "dccb9e68b0790c40f8faff69fa697c8136043d379f2dce70aab7b594ffcf3d36"
110
110
  },
111
111
  "downloads": -1,
112
112
  "filename": "widgetsnbextension-4.0.11-py3-none-any.whl",
113
113
  "has_sig": false,
114
- "md5_digest": "7c782a5f84d0a85cf707be540b5c86ac",
114
+ "md5_digest": "e75f3f8c90eaf5ab63c79b2b22236395",
115
115
  "packagetype": "bdist_wheel",
116
116
  "python_version": "py3",
117
117
  "requires_python": "<3.12,>=3.11",
118
- "size": 2355,
119
- "upload_time": "2024-06-21T07:29:44.671026Z",
120
- "upload_time_iso_8601": "2024-06-21T07:29:44.671026Z",
118
+ "size": 2354,
119
+ "upload_time": "2024-07-23T12:47:35.829642Z",
120
+ "upload_time_iso_8601": "2024-07-23T12:47:35.829642Z",
121
121
  "url": "./widgetsnbextension-4.0.11-py3-none-any.whl",
122
122
  "yanked": false,
123
123
  "yanked_reason": null
index 531cd09..f338cba 100644
Binary file