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

Bootstrap environments using mambajs, allowing libraries handling for other kernels than xeus-python #130

Merged
merged 11 commits into from
Dec 17, 2024
35 changes: 35 additions & 0 deletions packages/xeus-extension/lab.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');

const wasmPath = [
__dirname,
'..',
'..',
'node_modules',
'@emscripten-forge',
'mambajs',
'lib',
'*.wasm'
];
const staticPath = [
__dirname,
'..',
'..',
'jupyterlite_xeus',
'labextension',
'static',
'[name].wasm'
];

module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(...wasmPath),
to: path.join(...staticPath)
}
]
})
]
};
2 changes: 2 additions & 0 deletions packages/xeus-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/json-schema": "^7.0.11",
"@types/react": "^18.0.26",
"@types/react-addons-linked-state-mixin": "^0.14.22",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.7.1",
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.1",
Expand All @@ -65,6 +66,7 @@
"jupyterlab": {
"extension": true,
"outputDir": "../../jupyterlite_xeus/labextension",
"webpackConfig": "lab.webpack.config.js",
"sharedPackages": {
"@jupyterlite/kernel": {
"bundled": false,
Expand Down
1 change: 1 addition & 0 deletions packages/xeus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"watch:src": "tsc -w --sourceMap"
},
"dependencies": {
"@emscripten-forge/mambajs": "^0.1.0",
"@jupyterlab/coreutils": "^6",
"@jupyterlab/services": "~7.2.5",
"@jupyterlite/contents": "^0.2.0 || ^0.3.0 || ^0.4.5",
Expand Down
41 changes: 27 additions & 14 deletions packages/xeus/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { URLExt } from '@jupyterlab/coreutils';

import { IXeusWorkerKernel } from './interfaces';

import { bootstrapFromEmpackPackedEnvironment, IPackagesInfo} from "@emscripten-forge/mambajs"
globalThis.Module = {};

// when a toplevel cell uses an await, the cell is implicitly
Expand Down Expand Up @@ -118,23 +118,38 @@ export class XeusRemoteKernel {
});
try {
await waitRunDependency();

if (globalThis.Module.FS !== undefined) {
martinRenou marked this conversation as resolved.
Show resolved Hide resolved
// 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 = empackEnvMetaLink

const kernel_root_url = empackEnvMetaLink
? empackEnvMetaLink
: URLExt.join(baseUrl, `xeus/kernels/${kernelSpec.dir}`);
const pkg_root_url = URLExt.join(baseUrl, 'xeus/kernel_packages');
const verbose = true;
await globalThis.Module['async_init'](
kernel_root_url,
pkg_root_url,
verbose
);
}
const verbose = true;

//if the kernel is not xeus-python than we have to avoid using pyjs

martinRenou marked this conversation as resolved.
Show resolved Hide resolved
const packagesJsonUrl = `${kernel_root_url}/empack_env_meta.json`;
const pkgRootUrl = URLExt.join(baseUrl, 'xeus/kernel_packages');

let packageData: IPackagesInfo = {};
try{
martinRenou marked this conversation as resolved.
Show resolved Hide resolved
packageData = await bootstrapFromEmpackPackedEnvironment(packagesJsonUrl, verbose, false, globalThis.Module, pkgRootUrl);
} catch(error: any) {

throw new Error(error.message);
}
martinRenou marked this conversation as resolved.
Show resolved Hide resolved
if (kernelSpec.name === 'xpython') {
if (Object.keys(packageData).length) {
let {pythonVersion, prefix} = packageData;
if (pythonVersion) {
globalThis.Module.init_phase_2(prefix, pythonVersion, verbose);
}
}
}
}

await waitRunDependency();

Expand All @@ -147,10 +162,8 @@ export class XeusRemoteKernel {
} catch (e) {
if (typeof e === 'number') {
const msg = globalThis.Module.get_exception_message(e);
console.error(msg);
throw new Error(msg);
} else {
console.error(e);
throw e;
}
}
Expand Down
61 changes: 59 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ __metadata:
"@types/json-schema": ^7.0.11
"@types/react": ^18.0.26
"@types/react-addons-linked-state-mixin": ^0.14.22
copy-webpack-plugin: ^12.0.2
css-loader: ^6.7.1
npm-run-all: ^4.1.5
rimraf: ^5.0.1
Expand Down Expand Up @@ -1388,6 +1389,13 @@ __metadata:
languageName: node
linkType: hard

"@sindresorhus/merge-streams@npm:^2.1.0":
version: 2.3.0
resolution: "@sindresorhus/merge-streams@npm:2.3.0"
checksum: e989d53dee68d7e49b4ac02ae49178d561c461144cea83f66fa91ff012d981ad0ad2340cbd13f2fdb57989197f5c987ca22a74eb56478626f04e79df84291159
languageName: node
linkType: hard

"@tufjs/canonical-json@npm:2.0.0":
version: 2.0.0
resolution: "@tufjs/canonical-json@npm:2.0.0"
Expand Down Expand Up @@ -2853,6 +2861,22 @@ __metadata:
languageName: node
linkType: hard

"copy-webpack-plugin@npm:^12.0.2":
version: 12.0.2
resolution: "copy-webpack-plugin@npm:12.0.2"
dependencies:
fast-glob: ^3.3.2
glob-parent: ^6.0.1
globby: ^14.0.0
normalize-path: ^3.0.0
schema-utils: ^4.2.0
serialize-javascript: ^6.0.2
peerDependencies:
webpack: ^5.1.0
checksum: 98127735336c6db5924688486d3a1854a41835963d0c0b81695b2e3d58c6675164be7d23dee7090b84a56d3c9923175d3d0863ac1942bcc3317d2efc1962b927
languageName: node
linkType: hard

"core-util-is@npm:~1.0.0":
version: 1.0.3
resolution: "core-util-is@npm:1.0.3"
Expand Down Expand Up @@ -3668,7 +3692,7 @@ __metadata:
languageName: node
linkType: hard

"fast-glob@npm:^3.2.9":
"fast-glob@npm:^3.2.9, fast-glob@npm:^3.3.2":
version: 3.3.2
resolution: "fast-glob@npm:3.3.2"
dependencies:
Expand Down Expand Up @@ -4088,7 +4112,7 @@ __metadata:
languageName: node
linkType: hard

"glob-parent@npm:6.0.2, glob-parent@npm:^6.0.2":
"glob-parent@npm:6.0.2, glob-parent@npm:^6.0.1, glob-parent@npm:^6.0.2":
version: 6.0.2
resolution: "glob-parent@npm:6.0.2"
dependencies:
Expand Down Expand Up @@ -6083,6 +6107,13 @@ __metadata:
languageName: node
linkType: hard

"normalize-path@npm:^3.0.0":
version: 3.0.0
resolution: "normalize-path@npm:3.0.0"
checksum: 88eeb4da891e10b1318c4b2476b6e2ecbeb5ff97d946815ffea7794c31a89017c70d7f34b3c2ebf23ef4e9fc9fb99f7dffe36da22011b5b5c6ffa34f4873ec20
languageName: node
linkType: hard

"npm-bundled@npm:^3.0.0":
version: 3.0.1
resolution: "npm-bundled@npm:3.0.1"
Expand Down Expand Up @@ -7385,6 +7416,18 @@ __metadata:
languageName: node
linkType: hard

"schema-utils@npm:^4.2.0":
version: 4.3.0
resolution: "schema-utils@npm:4.3.0"
dependencies:
"@types/json-schema": ^7.0.9
ajv: ^8.9.0
ajv-formats: ^2.1.1
ajv-keywords: ^5.1.0
checksum: 3dbd9056727c871818eaf3cabeeb5c9e173ae2b17bbf2a9c7a2e49c220fa1a580e44df651c876aea3b4926cecf080730a39e28202cb63f2b68d99872b49cd37a
languageName: node
linkType: hard

"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.4.1, semver@npm:^5.5.0, semver@npm:^5.6.0":
version: 5.7.2
resolution: "semver@npm:5.7.2"
Expand Down Expand Up @@ -7576,6 +7619,13 @@ __metadata:
languageName: node
linkType: hard

"slash@npm:^5.1.0":
version: 5.1.0
resolution: "slash@npm:5.1.0"
checksum: 70434b34c50eb21b741d37d455110258c42d2cf18c01e6518aeb7299f3c6e626330c889c0c552b5ca2ef54a8f5a74213ab48895f0640717cacefeef6830a1ba4
languageName: node
linkType: hard

"smart-buffer@npm:^4.2.0":
version: 4.2.0
resolution: "smart-buffer@npm:4.2.0"
Expand Down Expand Up @@ -8364,6 +8414,13 @@ __metadata:
languageName: node
linkType: hard

"unicorn-magic@npm:^0.1.0":
version: 0.1.0
resolution: "unicorn-magic@npm:0.1.0"
checksum: 48c5882ca3378f380318c0b4eb1d73b7e3c5b728859b060276e0a490051d4180966beeb48962d850fd0c6816543bcdfc28629dcd030bb62a286a2ae2acb5acb6
languageName: node
linkType: hard

"unique-filename@npm:^3.0.0":
version: 3.0.0
resolution: "unique-filename@npm:3.0.0"
Expand Down
Loading