Skip to content

Commit

Permalink
Use new mambajs splitted API (#154)
Browse files Browse the repository at this point in the history
* Update mambajs

* Iterate

* Up 0.3.0

* Fixing
  • Loading branch information
martinRenou authored Jan 17, 2025
1 parent a060f02 commit f115ff5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/xeus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"watch:src": "tsc -w --sourceMap"
},
"dependencies": {
"@emscripten-forge/mambajs": "^0.2.2",
"@emscripten-forge/mambajs": "^0.3.0",
"@jupyterlab/coreutils": "^6",
"@jupyterlab/services": "^7.3.4",
"@jupyterlite/contents": "^0.2.0 || ^0.3.0 || ^0.4.5 || ^0.5.0",
Expand Down
57 changes: 47 additions & 10 deletions packages/xeus/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import { URLExt } from '@jupyterlab/coreutils';

import { IXeusWorkerKernel } from './interfaces';
import { bootstrapFromEmpackPackedEnvironment } from '@emscripten-forge/mambajs';
import {
IEmpackEnvMeta,
bootstrapEmpackPackedEnvironment,
bootstrapPython,
getPythonVersion,
loadShareLibs
} from '@emscripten-forge/mambajs';
globalThis.Module = {};

// when a toplevel cell uses an await, the cell is implicitly
Expand Down Expand Up @@ -33,6 +39,15 @@ async function get_stdin() {
return replyPromise;
}

async function fetchJson(url: string): Promise<any> {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const json = await response.json();
return json;
}

(self as any).get_stdin = get_stdin;

async function waitRunDependency() {
Expand Down Expand Up @@ -143,19 +158,41 @@ export class XeusRemoteKernel {
globalThis.Module.loadDynamicLibrary !== undefined
) {
const empackEnvMetaLocation = empackEnvMetaLink || kernel_root_url;
const verbose = true;
const packagesJsonUrl = `${empackEnvMetaLocation}/empack_env_meta.json`;
const pkgRootUrl = URLExt.join(baseUrl, 'xeus/kernel_packages');
const bootstrapPython = kernelSpec.name === 'xpython';

await bootstrapFromEmpackPackedEnvironment(
packagesJsonUrl,
verbose,
false,
globalThis.Module,
const empackEnvMeta = (await fetchJson(
packagesJsonUrl
)) as IEmpackEnvMeta;

const sharedLibs = await bootstrapEmpackPackedEnvironment({
empackEnvMeta,
pkgRootUrl,
bootstrapPython
);
Module: globalThis.Module,
verbose: true
});

// Bootstrap Python, if it's xeus-python
if (kernelSpec.name === 'xpython') {
const pythonVersion = getPythonVersion(empackEnvMeta.packages);

if (!pythonVersion) {
throw new Error('Failed to load Python!');
}

await bootstrapPython({
prefix: empackEnvMeta.prefix,
pythonVersion: pythonVersion,
Module: globalThis.Module
});
}

// Load shared libs
await loadShareLibs({
sharedLibs,
prefix: empackEnvMeta.prefix,
Module: globalThis.Module
});
}

await waitRunDependency();
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ __metadata:
languageName: node
linkType: hard

"@emscripten-forge/mambajs@npm:^0.2.2":
version: 0.2.2
resolution: "@emscripten-forge/mambajs@npm:0.2.2"
"@emscripten-forge/mambajs@npm:^0.3.0":
version: 0.3.0
resolution: "@emscripten-forge/mambajs@npm:0.3.0"
dependencies:
"@emscripten-forge/untarjs": ^5.0.0
checksum: 5b7ec3b01bca192cb225fed682071ca57f7ab6b7297ecff91cfaf4274f627e4321a8b7b5f709fbecadbaf31798efffc1597cd0110e497730cd5991552148373a
checksum: 1fecd2181706323b3ee9244444d1a1015452657746e3c8ca8a3431ec93193868533f111a877a654073cd54a6c7d8a5d72113fb338dbf58464bb4096edd7e6d89
languageName: node
linkType: hard

Expand Down Expand Up @@ -526,7 +526,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyterlite/xeus@workspace:packages/xeus"
dependencies:
"@emscripten-forge/mambajs": ^0.2.2
"@emscripten-forge/mambajs": ^0.3.0
"@jupyterlab/builder": ^4.1.0
"@jupyterlab/coreutils": ^6
"@jupyterlab/services": ^7.3.4
Expand Down

0 comments on commit f115ff5

Please sign in to comment.