Implement PyScript custom <script type> (#1548)

* updated MicroPython to latest in order to have `globals` API available
  * reduced code around helpers for both MicroPython and Pyodide as now these are more aligned
  * updated all dependencies and brought in latest [coincident/window](https://github.com/WebReflection/coincident#coincidentwindow) goodness to any `xworker`, preserving the `sync` previous behavior
  * using [@ungap/structured-clone/json](https://github.com/ungap/structured-clone#tojson) as *coincident* default `parse` and `stringify` utility to allow recursive and more complex data to travel back from the *Worker* (forward data is still fully [structured clone algorithm compatible](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm))
  * renamed all *plugin/s* references to *custom/s* as plugin as a word was too misleading
  * changed *custom types* helpers logic to allow any single node to have its own version of the interpreter wrapper, and all the extra fields it carries with it, including a way to augment every interpreter execution, among as every worker code execution
  * created a `custom` folder where I've landed the very first `pyscript.js` custom type
  * created an exhaustive test page to demonstrate the current abilities of *PyScript Next* among its ability to expose utilities that can be used to create *PyScript* plugins
This commit is contained in:
Andrea Giammarchi
2023-06-22 17:29:07 +02:00
committed by GitHub
parent 0a7e1ce0d7
commit f6dfc5361e
49 changed files with 634 additions and 283 deletions

View File

@@ -1,5 +1,11 @@
import { fetchPaths, stdio } from "./_utils.js";
import { run, runAsync, writeFile } from "./_python.js";
import {
run,
runAsync,
setGlobal,
deleteGlobal,
writeFile,
} from "./_python.js";
const type = "micropython";
@@ -7,7 +13,7 @@ const type = "micropython";
/* c8 ignore start */
export default {
type,
module: (version = "1.20.0-239") =>
module: (version = "1.20.0-253") =>
`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${version}/micropython.mjs`,
async engine({ loadMicroPython }, config, url) {
const { stderr, stdout, get } = stdio();
@@ -16,16 +22,8 @@ export default {
if (config.fetch) await fetchPaths(this, runtime, config.fetch);
return runtime;
},
setGlobal(interpreter, name, value) {
const id = `__pyscript_${this.type}_${name}`;
globalThis[id] = value;
this.run(interpreter, `from js import ${id};${name}=${id};`);
},
deleteGlobal(interpreter, name) {
const id = `__pyscript_${this.type}_${name}`;
this.run(interpreter, `del ${id};del ${name}`);
delete globalThis[id];
},
setGlobal,
deleteGlobal,
run,
runAsync,
writeFile,