mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
WIP: Bringing PyScript.next PoC to the main project (#1507)
* kill unwrapped_remote (#1490) * kill unwrapped_remote * linting * don't use callKwargs for python plugins * fix tests and improve types * Bringing PyScript.next PoC to the main project * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
4467898473
commit
339e40063a
35
pyscript.core/esm/runtime/micropython.js
Normal file
35
pyscript.core/esm/runtime/micropython.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { fetchPaths, stdio, writeFile } from "./_utils.js";
|
||||
|
||||
const type = "micropython";
|
||||
|
||||
// REQUIRES INTEGRATION TEST
|
||||
/* c8 ignore start */
|
||||
const worker = (method) =>
|
||||
function (runtime, code, xworker) {
|
||||
globalThis.xworker = xworker;
|
||||
return this[method](runtime, `from js import xworker;${code}`);
|
||||
};
|
||||
|
||||
export default {
|
||||
type: [type, "mpy"],
|
||||
module: () => `http://localhost:8080/micropython/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;
|
||||
},
|
||||
run: (runtime, code) => runtime.runPython(code),
|
||||
runAsync: (runtime, code) => runtime.runPythonAsync(code),
|
||||
runEvent(runtime, code, key) {
|
||||
return this.run(
|
||||
runtime,
|
||||
`import js;event=js.__events.get(${key});${code}`,
|
||||
);
|
||||
},
|
||||
runWorker: worker("run"),
|
||||
runWorkerAsync: worker("runAsync"),
|
||||
writeFile: ({ FS }, path, buffer) => writeFile(FS, path, buffer),
|
||||
};
|
||||
/* c8 ignore stop */
|
||||
Reference in New Issue
Block a user