@jupyterlite/pyodide-kernel 0.6.0-alpha.4 → 0.6.0-alpha.6

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/kernel.d.ts CHANGED
@@ -112,6 +112,7 @@ export declare class PyodideKernel extends BaseKernel implements IKernel {
112
112
  private _worker;
113
113
  private _remoteKernel;
114
114
  private _ready;
115
+ private _inputDelegate;
115
116
  }
116
117
  /**
117
118
  * A namespace for PyodideKernel statics.
@@ -153,5 +154,11 @@ export declare namespace PyodideKernel {
153
154
  * The Jupyterlite content manager
154
155
  */
155
156
  contentsManager: Contents.IManager;
157
+ /**
158
+ * A unique ID to identify the origin of this request.
159
+ * This should be provided by `IServiceWorkerManager` and is used to
160
+ * identify the browsing context from which the request originated.
161
+ */
162
+ browsingContextId?: string;
156
163
  }
157
164
  }
package/lib/kernel.js CHANGED
@@ -17,6 +17,7 @@ export class PyodideKernel extends BaseKernel {
17
17
  constructor(options) {
18
18
  super(options);
19
19
  this._ready = new PromiseDelegate();
20
+ this._inputDelegate = new PromiseDelegate();
20
21
  this._worker = this.initWorker(options);
21
22
  this._remoteKernel = this.initRemote(options);
22
23
  this._contentsManager = options.contentsManager;
@@ -65,6 +66,16 @@ export class PyodideKernel extends BaseKernel {
65
66
  }
66
67
  return await this._contentsProcessor.processDriveRequest(data);
67
68
  };
69
+ remote.processStdinRequest =
70
+ async (content) => {
71
+ const msg = {
72
+ type: 'input_request',
73
+ content,
74
+ };
75
+ this._processWorkerMessage(msg);
76
+ this._inputDelegate = new PromiseDelegate();
77
+ return await this._inputDelegate.promise;
78
+ };
68
79
  }
69
80
  else {
70
81
  remote = wrap(this._worker);
@@ -97,6 +108,7 @@ export class PyodideKernel extends BaseKernel {
97
108
  location: this.location,
98
109
  mountDrive: options.mountDrive,
99
110
  loadPyodideOptions: options.loadPyodideOptions || {},
111
+ browsingContextId: options.browsingContextId,
100
112
  };
101
113
  }
102
114
  /**
@@ -284,6 +296,7 @@ export class PyodideKernel extends BaseKernel {
284
296
  * @param content - The content of the reply.
285
297
  */
286
298
  async inputReply(content) {
287
- return await this._remoteKernel.inputReply(content, this.parent);
299
+ const value = 'value' in content ? content.value : undefined;
300
+ this._inputDelegate.resolve(value);
288
301
  }
289
302
  }
package/lib/tokens.d.ts CHANGED
@@ -30,6 +30,21 @@ export interface IPyodideWorkerKernel extends IWorkerKernel {
30
30
  */
31
31
  registerCallback(callback: (msg: any) => void): void;
32
32
  }
33
+ /**
34
+ * An interface for Coincident Pyodide workers that include extra SharedArrayBuffer
35
+ * functionality.
36
+ */
37
+ export interface ICoincidentPyodideWorkerKernel extends IPyodideWorkerKernel {
38
+ /**
39
+ * Process stdin request, blocking until the reply is received.
40
+ * This is sync for the web worker, async for the UI thread.
41
+ * @param inputRequest
42
+ */
43
+ processStdinRequest(content: {
44
+ prompt: string;
45
+ password: boolean;
46
+ }): string | undefined;
47
+ }
33
48
  /**
34
49
  * Deprecated.
35
50
  */
@@ -70,6 +85,12 @@ export declare namespace IPyodideWorkerKernel {
70
85
  * Whether or not to mount the Emscripten drive
71
86
  */
72
87
  mountDrive: boolean;
88
+ /**
89
+ * A unique ID to identify the origin of this request.
90
+ * This should be provided by `IServiceWorkerManager` and is used to
91
+ * identify the browsing context from which the request originated.
92
+ */
93
+ browsingContextId?: string;
73
94
  /**
74
95
  * additional options to provide to `loadPyodide`
75
96
  * @see https://pyodide.org/en/stable/usage/api/js-api.html#globalThis.loadPyodide
package/lib/worker.d.ts CHANGED
@@ -2,7 +2,7 @@ import type Pyodide from 'pyodide';
2
2
  import type { DriveFS } from '@jupyterlite/contents';
3
3
  import { KernelMessage } from '@jupyterlab/services';
4
4
  import type { IPyodideWorkerKernel } from './tokens';
5
- export declare class PyodideRemoteKernel {
5
+ export declare abstract class PyodideRemoteKernel {
6
6
  constructor();
7
7
  /**
8
8
  * Accept the URLs from the host
@@ -97,14 +97,15 @@ export declare class PyodideRemoteKernel {
97
97
  */
98
98
  inputReply(content: any, parent: any): Promise<void>;
99
99
  /**
100
- * Send a input request to the front-end.
100
+ * Send a input request to the front-end and block until the reply is received.
101
101
  *
102
102
  * @param prompt the text to show at the prompt
103
103
  * @param password Is the request for a password?
104
+ * @returns String value from the input reply message, or undefined if there is none.
104
105
  */
105
- sendInputRequest(prompt: string, password: boolean): Promise<void>;
106
- getpass(prompt: string): Promise<any>;
107
- input(prompt: string): Promise<any>;
106
+ protected abstract sendInputRequest(prompt: string, password: boolean): string | undefined;
107
+ getpass(prompt: string): string | undefined;
108
+ input(prompt: string): string | undefined;
108
109
  /**
109
110
  * Send a comm message to the front-end.
110
111
  *
@@ -128,11 +129,11 @@ export declare class PyodideRemoteKernel {
128
129
  /** TODO: real typing */
129
130
  protected _localPath: string;
130
131
  protected _driveName: string;
132
+ protected _browsingContextId: string | undefined;
131
133
  protected _kernel: any;
132
134
  protected _interpreter: any;
133
135
  protected _stdout_stream: any;
134
136
  protected _stderr_stream: any;
135
- protected _resolveInputReply: any;
136
137
  protected _driveFS: DriveFS | null;
137
138
  protected _sendWorkerMessage: (msg: any) => void;
138
139
  }
package/lib/worker.js CHANGED
@@ -130,6 +130,7 @@ export class PyodideRemoteKernel {
130
130
  baseUrl,
131
131
  driveName: this._driveName,
132
132
  mountpoint,
133
+ browsingContextId: this._browsingContextId,
133
134
  });
134
135
  FS.mkdirTree(mountpoint);
135
136
  FS.mount(driveFS, {}, mountpoint);
@@ -357,43 +358,16 @@ export class PyodideRemoteKernel {
357
358
  * @param content The incoming message with the reply
358
359
  */
359
360
  async inputReply(content, parent) {
360
- await this.setup(parent);
361
- this._resolveInputReply(content);
361
+ // Should never be called as input_reply messages are returned via service worker
362
+ // or SharedArrayBuffer.
362
363
  }
363
- /**
364
- * Send a input request to the front-end.
365
- *
366
- * @param prompt the text to show at the prompt
367
- * @param password Is the request for a password?
368
- */
369
- async sendInputRequest(prompt, password) {
370
- const content = {
371
- prompt,
372
- password,
373
- };
374
- this._sendWorkerMessage({
375
- type: 'input_request',
376
- parentHeader: this.formatResult(this._kernel._parent_header)['header'],
377
- content,
378
- });
379
- }
380
- async getpass(prompt) {
364
+ getpass(prompt) {
381
365
  prompt = typeof prompt === 'undefined' ? '' : prompt;
382
- await this.sendInputRequest(prompt, true);
383
- const replyPromise = new Promise((resolve) => {
384
- this._resolveInputReply = resolve;
385
- });
386
- const result = await replyPromise;
387
- return result['value'];
366
+ return this.sendInputRequest(prompt, true);
388
367
  }
389
- async input(prompt) {
368
+ input(prompt) {
390
369
  prompt = typeof prompt === 'undefined' ? '' : prompt;
391
- await this.sendInputRequest(prompt, false);
392
- const replyPromise = new Promise((resolve) => {
393
- this._resolveInputReply = resolve;
394
- });
395
- const result = await replyPromise;
396
- return result['value'];
370
+ return this.sendInputRequest(prompt, false);
397
371
  }
398
372
  /**
399
373
  * Send a comm message to the front-end.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/pyodide-kernel",
3
- "version": "0.6.0-alpha.4",
3
+ "version": "0.6.0-alpha.6",
4
4
  "description": "JupyterLite - Pyodide Kernel",
5
5
  "homepage": "https://github.com/jupyterlite/pyodide-kernel",
6
6
  "bugs": {
@@ -50,16 +50,16 @@
50
50
  "watch": "tsc -b --watch"
51
51
  },
52
52
  "dependencies": {
53
- "@jupyterlab/coreutils": "^6.4.0-beta.1",
54
- "@jupyterlite/contents": "^0.6.0-alpha.3",
55
- "@jupyterlite/kernel": "^0.6.0-alpha.3",
53
+ "@jupyterlab/coreutils": "^6.4.0",
54
+ "@jupyterlite/contents": "^0.6.0-alpha.8",
55
+ "@jupyterlite/kernel": "^0.6.0-alpha.8",
56
56
  "coincident": "^1.2.3",
57
57
  "comlink": "^4.4.2"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@babel/core": "^7.22.17",
61
61
  "esbuild": "^0.19.2",
62
- "pyodide": "0.27.4",
62
+ "pyodide": "0.27.5",
63
63
  "rimraf": "^5.0.1",
64
64
  "typescript": "~5.2.2"
65
65
  },
@@ -68,8 +68,8 @@
68
68
  },
69
69
  "pyodide-kernel": {
70
70
  "packages": {
71
- "py/pyodide-kernel": "0.6.0a4",
72
- "py/piplite": "0.6.0a4",
71
+ "py/pyodide-kernel": "0.6.0a6",
72
+ "py/piplite": "0.6.0a6",
73
73
  "py/ipykernel": "6.9.2",
74
74
  "py/widgetsnbextension3/widgetsnbextension": "3.6.999",
75
75
  "py/widgetsnbextension4/widgetsnbextension": "4.0.999"
package/pypi/all.json CHANGED
@@ -5,19 +5,19 @@
5
5
  {
6
6
  "comment_text": "",
7
7
  "digests": {
8
- "md5": "259499dfb96efde47aa0282950b7087e",
9
- "sha256": "86f1d14550a3e7fe983ec19f9f21f2409175de9bef3438970fd6910f265d4a19"
8
+ "md5": "c4a1c70e9d300eaa77da2573911088c8",
9
+ "sha256": "17c7aa29892f2724ee3bea223e2565a5a492c38953db901e1b528582670bd510"
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": "259499dfb96efde47aa0282950b7087e",
14
+ "md5_digest": "c4a1c70e9d300eaa77da2573911088c8",
15
15
  "packagetype": "bdist_wheel",
16
16
  "python_version": "py3",
17
17
  "requires_python": ">=3.10",
18
18
  "size": 2731,
19
- "upload_time": "2025-03-19T13:39:39.970095Z",
20
- "upload_time_iso_8601": "2025-03-19T13:39:39.970095Z",
19
+ "upload_time": "2025-05-07T18:41:19.083517Z",
20
+ "upload_time_iso_8601": "2025-05-07T18:41:19.083517Z",
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.6.0a4": [
30
+ "0.6.0a6": [
31
31
  {
32
32
  "comment_text": "",
33
33
  "digests": {
34
- "md5": "34b0d1c22284eec87a4aeaef387c445e",
35
- "sha256": "1eca57ee12bea7ee279c42b831d5f521da49014bab1564365b2864926802d1aa"
34
+ "md5": "d09f7d8ce9121e2befca9bae84cd54b1",
35
+ "sha256": "77a42f2dbc285e0609265f5255007e2d978127eeaf7b0b2898547980fb347057"
36
36
  },
37
37
  "downloads": -1,
38
- "filename": "piplite-0.6.0a4-py3-none-any.whl",
38
+ "filename": "piplite-0.6.0a6-py3-none-any.whl",
39
39
  "has_sig": false,
40
- "md5_digest": "34b0d1c22284eec87a4aeaef387c445e",
40
+ "md5_digest": "d09f7d8ce9121e2befca9bae84cd54b1",
41
41
  "packagetype": "bdist_wheel",
42
42
  "python_version": "py3",
43
43
  "requires_python": "<3.12,>=3.11",
44
44
  "size": 7254,
45
- "upload_time": "2025-03-19T13:39:39.970095Z",
46
- "upload_time_iso_8601": "2025-03-19T13:39:39.970095Z",
47
- "url": "./piplite-0.6.0a4-py3-none-any.whl",
45
+ "upload_time": "2025-05-07T18:41:19.082517Z",
46
+ "upload_time_iso_8601": "2025-05-07T18:41:19.082517Z",
47
+ "url": "./piplite-0.6.0a6-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.6.0a4": [
56
+ "0.6.0a6": [
57
57
  {
58
58
  "comment_text": "",
59
59
  "digests": {
60
- "md5": "69a2f0cf845fcbc372da93ef054d1be4",
61
- "sha256": "1f45c36327aa23e3d8bb3888b53abaa2b5c78376a26c98d27183a8162626f984"
60
+ "md5": "b59091b6a2b8c754f1967c95aa015ede",
61
+ "sha256": "014b4d106f6428930c0c582bd01355133d4a1b5ac8cdb664b9ef667e999b8d90"
62
62
  },
63
63
  "downloads": -1,
64
- "filename": "pyodide_kernel-0.6.0a4-py3-none-any.whl",
64
+ "filename": "pyodide_kernel-0.6.0a6-py3-none-any.whl",
65
65
  "has_sig": false,
66
- "md5_digest": "69a2f0cf845fcbc372da93ef054d1be4",
66
+ "md5_digest": "b59091b6a2b8c754f1967c95aa015ede",
67
67
  "packagetype": "bdist_wheel",
68
68
  "python_version": "py3",
69
69
  "requires_python": "<3.12,>=3.11",
70
- "size": 11412,
71
- "upload_time": "2025-03-19T13:39:39.969095Z",
72
- "upload_time_iso_8601": "2025-03-19T13:39:39.969095Z",
73
- "url": "./pyodide_kernel-0.6.0a4-py3-none-any.whl",
70
+ "size": 11411,
71
+ "upload_time": "2025-05-07T18:41:19.082517Z",
72
+ "upload_time_iso_8601": "2025-05-07T18:41:19.082517Z",
73
+ "url": "./pyodide_kernel-0.6.0a6-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": "94bb712be1bc5de651121aa1fa9efb2f",
87
- "sha256": "eb9844f4d5fd6d299aaf91388607abbde442c968676c95fde2d7b6717a2e4b8a"
86
+ "md5": "c60448da43a2c5fea845219309483d09",
87
+ "sha256": "901e64c7ae4560bd8f77ba92ee7011be85b06eff743b7d6c1fc45718601dce9d"
88
88
  },
89
89
  "downloads": -1,
90
90
  "filename": "widgetsnbextension-3.6.999-py3-none-any.whl",
91
91
  "has_sig": false,
92
- "md5_digest": "94bb712be1bc5de651121aa1fa9efb2f",
92
+ "md5_digest": "c60448da43a2c5fea845219309483d09",
93
93
  "packagetype": "bdist_wheel",
94
94
  "python_version": "py3",
95
95
  "requires_python": "<3.12,>=3.11",
96
96
  "size": 2369,
97
- "upload_time": "2025-03-19T13:39:39.970095Z",
98
- "upload_time_iso_8601": "2025-03-19T13:39:39.970095Z",
97
+ "upload_time": "2025-05-07T18:41:19.083517Z",
98
+ "upload_time_iso_8601": "2025-05-07T18:41:19.083517Z",
99
99
  "url": "./widgetsnbextension-3.6.999-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": "b647092d262df3cb54776b8cc015bcfb",
109
- "sha256": "249fbdd469be152de5bf627b71938b42154506a91e6992e5e4340fa28916434d"
108
+ "md5": "ef8e80f38311771d1cd24c206ce62c59",
109
+ "sha256": "343b63612da12c37086ae06885b8202e814a5d35154dcece93083f39517e3e39"
110
110
  },
111
111
  "downloads": -1,
112
112
  "filename": "widgetsnbextension-4.0.999-py3-none-any.whl",
113
113
  "has_sig": false,
114
- "md5_digest": "b647092d262df3cb54776b8cc015bcfb",
114
+ "md5_digest": "ef8e80f38311771d1cd24c206ce62c59",
115
115
  "packagetype": "bdist_wheel",
116
116
  "python_version": "py3",
117
117
  "requires_python": "<3.12,>=3.11",
118
118
  "size": 2370,
119
- "upload_time": "2025-03-19T13:39:39.970095Z",
120
- "upload_time_iso_8601": "2025-03-19T13:39:39.970095Z",
119
+ "upload_time": "2025-05-07T18:41:19.083517Z",
120
+ "upload_time_iso_8601": "2025-05-07T18:41:19.083517Z",
121
121
  "url": "./widgetsnbextension-4.0.999-py3-none-any.whl",
122
122
  "yanked": false,
123
123
  "yanked_reason": null
index bc159b7..e76f09d 100644
Binary file