@jupyterlite/pyodide-kernel 0.4.0-alpha.1 → 0.4.0-beta.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,5 @@
1
1
  export * from './_pypi';
2
- export * from './comlink.worker';
2
+ export * from './coincident.worker';
3
3
  export * from './kernel';
4
4
  export * from './tokens';
5
5
  export * from './worker';
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
  export * from './_pypi';
4
- export * from './comlink.worker';
4
+ export * from './coincident.worker';
5
5
  export * from './kernel';
6
6
  export * from './tokens';
7
7
  export * from './worker';
package/lib/kernel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { KernelMessage } from '@jupyterlab/services';
1
+ import { Contents, KernelMessage } from '@jupyterlab/services';
2
2
  import { BaseKernel, IKernel } from '@jupyterlite/kernel';
3
3
  import { IPyodideWorkerKernel } from './tokens';
4
4
  /**
@@ -11,6 +11,7 @@ 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;
14
15
  /**
15
16
  * Load the worker.
16
17
  *
@@ -20,7 +21,7 @@ export declare class PyodideKernel extends BaseKernel implements IKernel {
20
21
  * webpack to find it.
21
22
  */
22
23
  protected initWorker(options: PyodideKernel.IOptions): Worker;
23
- protected initRemote(options: PyodideKernel.IOptions): Promise<void>;
24
+ protected initRemote(options: PyodideKernel.IOptions): IPyodideWorkerKernel;
24
25
  protected initRemoteOptions(options: PyodideKernel.IOptions): IPyodideWorkerKernel.IOptions;
25
26
  /**
26
27
  * Dispose the kernel.
@@ -100,6 +101,8 @@ export declare class PyodideKernel extends BaseKernel implements IKernel {
100
101
  * @param content - The content of the reply.
101
102
  */
102
103
  inputReply(content: KernelMessage.IInputReplyMsg['content']): Promise<void>;
104
+ private _contentsManager;
105
+ private _contentsProcessor;
103
106
  private _worker;
104
107
  private _remoteKernel;
105
108
  private _ready;
@@ -140,5 +143,9 @@ export declare namespace PyodideKernel {
140
143
  lockFileURL: string;
141
144
  packages: string[];
142
145
  };
146
+ /**
147
+ * The Jupyterlite content manager
148
+ */
149
+ contentsManager: Contents.IManager;
143
150
  }
144
151
  }
package/lib/kernel.js CHANGED
@@ -1,8 +1,9 @@
1
+ import coincident from 'coincident';
1
2
  import { PromiseDelegate } from '@lumino/coreutils';
2
3
  import { PageConfig } from '@jupyterlab/coreutils';
3
4
  import { BaseKernel } from '@jupyterlite/kernel';
4
- import { wrap } from 'comlink';
5
5
  import { allJSONUrl, pipliteWheelUrl } from './_pypi';
6
+ import { DriveContentsProcessor, } from '@jupyterlite/contents';
6
7
  /**
7
8
  * A kernel that executes Python code with Pyodide.
8
9
  */
@@ -17,8 +18,22 @@ export class PyodideKernel extends BaseKernel {
17
18
  this._ready = new PromiseDelegate();
18
19
  this._worker = this.initWorker(options);
19
20
  this._worker.onmessage = (e) => this._processWorkerMessage(e.data);
20
- this._remoteKernel = wrap(this._worker);
21
- this.initRemote(options);
21
+ this._remoteKernel = this.initRemote(options);
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
+ };
22
37
  }
23
38
  /**
24
39
  * Load the worker.
@@ -29,14 +44,15 @@ export class PyodideKernel extends BaseKernel {
29
44
  * webpack to find it.
30
45
  */
31
46
  initWorker(options) {
32
- return new Worker(new URL('./comlink.worker.js', import.meta.url), {
47
+ return new Worker(new URL('./coincident.worker.js', import.meta.url), {
33
48
  type: 'module',
34
49
  });
35
50
  }
36
- async initRemote(options) {
51
+ initRemote(options) {
52
+ const remote = coincident(this._worker);
37
53
  const remoteOptions = this.initRemoteOptions(options);
38
- await this._remoteKernel.initialize(remoteOptions);
39
- this._ready.resolve();
54
+ remote.initialize(remoteOptions).then(this._ready.resolve.bind(this._ready));
55
+ return remote;
40
56
  }
41
57
  initRemoteOptions(options) {
42
58
  const { pyodideUrl } = options;
package/lib/tokens.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Definitions for the Pyodide kernel.
3
3
  */
4
- import type { Remote } from 'comlink';
4
+ import { TDriveMethod, TDriveRequest, TDriveResponse } from '@jupyterlite/contents';
5
5
  import { IWorkerKernel } from '@jupyterlite/kernel';
6
6
  /**
7
7
  * The schema for a Warehouse-like index, as used by piplite.
@@ -15,11 +15,16 @@ export interface IPyodideWorkerKernel extends IWorkerKernel {
15
15
  * Handle any lazy initialization activities.
16
16
  */
17
17
  initialize(options: IPyodideWorkerKernel.IOptions): Promise<void>;
18
+ /**
19
+ * Process drive request
20
+ * @param data
21
+ */
22
+ processDriveRequest<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;
18
23
  }
19
24
  /**
20
- * An convenience interface for Pyodide workers wrapped by a comlink Remote.
25
+ * Deprecated.
21
26
  */
22
- export type IRemotePyodideWorkerKernel = Remote<IPyodideWorkerKernel>;
27
+ export type IRemotePyodideWorkerKernel = IPyodideWorkerKernel;
23
28
  /**
24
29
  * An namespace for Pyodide workers.
25
30
  */
package/lib/worker.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type Pyodide from 'pyodide';
2
2
  import type { DriveFS } from '@jupyterlite/contents';
3
+ import { KernelMessage } from '@jupyterlab/services';
3
4
  import type { IPyodideWorkerKernel } from './tokens';
4
5
  export declare class PyodideRemoteKernel {
5
6
  constructor();
@@ -65,10 +66,7 @@ export declare class PyodideRemoteKernel {
65
66
  *
66
67
  * @param content The incoming message with the comm target name.
67
68
  */
68
- commInfo(content: any, parent: any): Promise<{
69
- comms: any;
70
- status: string;
71
- }>;
69
+ commInfo(content: any, parent: any): Promise<KernelMessage.ICommInfoReplyMsg['content']>;
72
70
  /**
73
71
  * Respond to the commOpen.
74
72
  *