Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup pass #9

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const kernel_specs = kernel_dir.map(kernel_dir => {

console.log(kernel_specs);

const server_kernels = kernel_specs.map(spec => {
const server_kernels = kernel_specs.map(kernelspec => {
const server_kernel: JupyterLiteServerPlugin<void> = {
// use name from spec
id: `@jupyterlite/${spec.name}-extension:kernel`,
id: `@jupyterlite/${kernelspec.name}-extension:kernel`,
autoStart: true,
requires: [IKernelSpecs],
optional: [IServiceWorkerManager, IBroadcastChannelWrapper],
Expand All @@ -73,7 +73,7 @@ const server_kernels = kernel_specs.map(spec => {
broadcastChannel?: IBroadcastChannelWrapper
) => {
kernelspecs.register({
spec: spec,
spec: kernelspec,
create: async (options: IKernel.IOptions): Promise<IKernel> => {
// const mountDrive = !!(
// serviceWorker?.enabled && broadcastChannel?.enabled
Expand All @@ -82,21 +82,19 @@ const server_kernels = kernel_specs.map(spec => {

if (mountDrive) {
console.info(
`${spec.name} contents will be synced with Jupyter Contents`
`${kernelspec.name} contents will be synced with Jupyter Contents`
);
} else {
console.warn(
`${spec.name} contents will NOT be synced with Jupyter Contents`
`${kernelspec.name} contents will NOT be synced with Jupyter Contents`
);
}

return new WebWorkerKernel(
{
...options,
mountDrive
},
spec
);
return new WebWorkerKernel({
...options,
mountDrive,
kernelspec
});
}
});
}
Expand Down
15 changes: 8 additions & 7 deletions src/web_worker_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export class WebWorkerKernel implements IKernel {
*
* @param options The instantiation options for a new WebWorkerKernel
*/
constructor(options: WebWorkerKernel.IOptions, spec: any) {
constructor(options: WebWorkerKernel.IOptions) {
console.log('constructing WebWorkerKernel kernel');
const { id, name, sendMessage, location } = options;
this._id = id;
this._name = name;
this._location = location;
this._spec = spec;
this._kernelspec = options.kernelspec;
this._sendMessage = sendMessage;
console.log('constructing WebWorkerKernel worker');
this._worker = new Worker(new URL('./worker.js', import.meta.url), {
Expand All @@ -54,10 +54,10 @@ export class WebWorkerKernel implements IKernel {
this._remote.processMessage({
msg: {
header: {
msg_type: 'initialize'
}
},
spec: this._spec
msg_type: '__initialize__'
},
kernelspec: this._kernelspec
}
});

console.log('init filesystem');
Expand Down Expand Up @@ -208,7 +208,7 @@ export class WebWorkerKernel implements IKernel {
}
}

private _spec: any;
private _kernelspec: any;
private _id: string;
private _name: string;
private _location: string;
Expand All @@ -233,5 +233,6 @@ export namespace WebWorkerKernel {
*/
export interface IOptions extends IKernel.IOptions {
mountDrive: boolean;
kernelspec: any;
}
}
29 changes: 13 additions & 16 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ declare function createXeusModule(options: any): any;

globalThis.Module = {};

console.log('worker here');

// const WASM_KERNEL_FILE = 'kernels/xlite/xlite.js';
// const WASM_FILE = 'kernels/xlite/xlite.wasm';
// TODO Remove this. This is to ensure we always perform node ops on Nodes and
// not Streams, but why is it needed??? Why do we get Streams and not Nodes from
// emscripten in the case of xeus-python???
class StreamNodeOps extends DriveFSEmscriptenNodeOps {
private getNode(nodeOrStream: any) {
if (nodeOrStream['node']) {
Expand Down Expand Up @@ -143,9 +136,8 @@ class XeusKernel {

async processMessage(event: any): Promise<void> {
const msg_type = event.msg.header.msg_type;
if (msg_type === 'initialize') {
const spec = event.spec;
this._spec = spec;
if (msg_type === '__initialize__') {
this._kernelspec = event.msg.kernelspec;
await this.initialize();

return;
Expand All @@ -171,12 +163,13 @@ class XeusKernel {
}

private async initialize() {
const dir = this._spec.dir;
const binary_js = this._spec.argv[0];
const binary_wasm = binary_js.replace('.js', '.wasm');
// the location of the kernel on the server
// ie `share/jupyter/kernels/${dir}`
const dir = this._kernelspec.dir;

console.log(binary_js);
console.log(binary_wasm);
// location of the kernel binary on the server
const binary_js = this._kernelspec.argv[0];
const binary_wasm = binary_js.replace('.js', '.wasm');

importScripts(binary_js);
globalThis.Module = await createXeusModule({
Expand All @@ -191,6 +184,10 @@ class XeusKernel {
await this.waitRunDependency();
console.log(globalThis.Module);

// each kernel can have a `async_init` function
// which can do kernel specific **async** initialization
// This function is usually implemented in the pre/post.js
// in the emscripten build of that kernel
if (globalThis.Module['async_init'] !== undefined) {
const kernel_root_url = `share/jupyter/kernels/${dir}`;
const pkg_root_url = 'share/jupyter/kernel_packages';
Expand Down Expand Up @@ -239,7 +236,7 @@ class XeusKernel {
return promise;
}
private _resolve: any;
private _spec: any;
private _kernelspec: any;
private _raw_xkernel: any;
private _raw_xserver: any;
private _drive: DriveFS | null = null;
Expand Down
Loading