fix(Code Node): Install python modules always in a user-writable folder (#6568)

* upgrade pyodide

* install pyodide modules to a custom user-writable path

* in `augmentObject` `newData` is never undefined
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-07-07 16:43:45 +02:00
committed by GitHub
parent 071e56f7fd
commit bf351243df
15 changed files with 98 additions and 77 deletions

View File

@@ -2,26 +2,15 @@ import type { PyodideInterface } from 'pyodide';
let pyodideInstance: PyodideInterface | undefined;
export async function LoadPyodide(): Promise<PyodideInterface> {
export async function LoadPyodide(packageCacheDir: string): Promise<PyodideInterface> {
if (pyodideInstance === undefined) {
// TODO: Find better way to suppress warnings
//@ts-ignore
globalThis.Blob = (await import('node:buffer')).Blob;
// From: https://github.com/nodejs/node/issues/30810
const { emitWarning } = process;
process.emitWarning = (warning, ...args) => {
if (args[0] === 'ExperimentalWarning') {
return;
}
if (args[0] && typeof args[0] === 'object' && args[0].type === 'ExperimentalWarning') {
return;
}
return emitWarning(warning, ...(args as string[]));
};
const { loadPyodide } = await import('pyodide');
pyodideInstance = await loadPyodide();
pyodideInstance = await loadPyodide({ packageCacheDir });
await pyodideInstance.runPythonAsync(`
from _pyodide_core import jsproxy_typedict
from js import Object
`);
}
return pyodideInstance;