PyScript Core Documentation (#1560)

This commit is contained in:
Andrea Giammarchi
2023-06-27 16:53:19 +02:00
committed by GitHub
parent bf6470c046
commit 9121071ba3
18 changed files with 627 additions and 69 deletions

View File

@@ -1,11 +1,5 @@
import { fetchPaths, stdio } from "./_utils.js";
import {
run,
runAsync,
setGlobal,
deleteGlobal,
writeFile,
} from "./_python.js";
import { run, setGlobal, deleteGlobal, writeFile } from "./_python.js";
const type = "micropython";
@@ -13,19 +7,23 @@ const type = "micropython";
/* c8 ignore start */
export default {
type,
module: (version = "1.20.0-253") =>
module: (version = "1.20.0-268") =>
`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${version}/micropython.mjs`,
async engine({ loadMicroPython }, config, url) {
const { stderr, stdout, get } = stdio();
url = url.replace(/\.m?js$/, ".wasm");
const runtime = await get(loadMicroPython({ stderr, stdout, url }));
if (config.fetch) await fetchPaths(this, runtime, config.fetch);
return runtime;
const interpreter = await get(loadMicroPython({ stderr, stdout, url }));
if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
return interpreter;
},
setGlobal,
deleteGlobal,
run,
runAsync,
// TODO: MicroPython doesn't have a Pyodide like top-level await,
// this method should still not throw errors once invoked
async runAsync(...args) {
return this.run(...args);
},
writeFile,
};
/* c8 ignore stop */