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

Python pools: Remove lockfile and indexURL arguments from getEmscriptenSettings #2935

Merged
merged 1 commit into from
Oct 16, 2024
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
21 changes: 10 additions & 11 deletions src/pyodide/internal/pool/emscriptenSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ function getInstantiateWasm(
* This isn't public API of Pyodide so it's a bit fiddly.
*/
function getEmscriptenSettings(
lockfile: PackageLock,
indexURL: string,
isWorkerd: boolean,
pythonStdlib: Uint8Array,
pyodideWasmModule: WebAssembly.Module
): EmscriptenSettings {
const config = {
const config: PyodideConfig = {
// jsglobals is used for the js module.
jsglobals: globalThis,
// environment variables go here
Expand All @@ -133,11 +132,13 @@ function getEmscriptenSettings(
// discussion in topLevelEntropy/entropy_patches.py
PYTHONHASHSEED: '111',
},
// This is the index that we use as the base URL to fetch the wheels.
indexURL,
};
// loadPackage initializes its state using lockFilePromise.
const lockFilePromise = lockfile ? Promise.resolve(lockfile) : undefined;
let lockFilePromise;
if (isWorkerd) {
lockFilePromise = new Promise(
(res) => (config.resolveLockFilePromise = res)
);
}
const API = { config, lockFilePromise };
let resolveReadyPromise: (mod: Module) => void;
const readyPromise: Promise<Module> = new Promise(
Expand Down Expand Up @@ -191,14 +192,12 @@ function* featureDetectionMonkeyPatchesContextManager() {
* Returns the instantiated emscriptenModule object.
*/
export async function instantiateEmscriptenModule(
lockfile: PackageLock,
indexURL: string,
isWorkerd: boolean,
pythonStdlib: Uint8Array,
wasmModule: WebAssembly.Module
): Promise<Module> {
const emscriptenSettings = getEmscriptenSettings(
lockfile,
indexURL,
isWorkerd,
pythonStdlib,
wasmModule
);
Expand Down
12 changes: 6 additions & 6 deletions src/pyodide/internal/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ async function prepareWasmLinearMemory(Module: Module): Promise<void> {
}

export async function loadPyodide(
isWorkerd: boolean,
lockfile: PackageLock,
indexURL: string
): Promise<Pyodide> {
const Module = await enterJaegerSpan('instantiate_emscripten', () =>
instantiateEmscriptenModule(
lockfile,
indexURL,
pythonStdlib,
pyodideWasmModule
)
instantiateEmscriptenModule(isWorkerd, pythonStdlib, pyodideWasmModule)
);
if (isWorkerd) {
Module.API.config.indexURL = indexURL;
Module.API.config.resolveLockFilePromise!(lockfile);
}
setUnsafeEval(UnsafeEval);
setGetRandomValues(getRandomValues);
await enterJaegerSpan('prepare_wasm_linear_memory', () =>
Expand Down
2 changes: 1 addition & 1 deletion src/pyodide/python-entrypoint-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getPyodide(): Promise<Pyodide> {
if (pyodidePromise) {
return pyodidePromise;
}
pyodidePromise = loadPyodide(LOCKFILE, WORKERD_INDEX_URL);
pyodidePromise = loadPyodide(IS_WORKERD, LOCKFILE, WORKERD_INDEX_URL);
return pyodidePromise;
});
}
Expand Down
12 changes: 9 additions & 3 deletions src/pyodide/types/emscripten.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
interface ENV {
HOME: string;
[k: string]: string;
}

interface PyodideConfig {
env: ENV;
jsglobals: any;
resolveLockFilePromise?: (lockfile: PackageLock) => void;
indexURL?: string;
}

interface API {
config: {
env: ENV;
};
config: PyodideConfig;
finalizeBootstrap: () => void;
public_api: Pyodide;
rawRun: (code: string) => [status: number, err: string];
Expand Down