diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5f2dcae7..9e09caf8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,13 +28,14 @@ repos: rev: v0.0.257 hooks: - id: ruff - exclude: pyscript\.core/test|pyscript\.core/dist|pyscript.core/src/stdlib/pyscript.py + exclude: pyscript\.core/src/stdlib/pyscript/__init__\.py|pyscript\.core/test|pyscript\.core/dist|pyscript\.core/src/stdlib/pyscript\.py args: [--fix] - repo: https://github.com/psf/black rev: 23.1.0 hooks: - id: black + exclude: pyscript\.core/src/stdlib/pyscript/__init__\.py - repo: https://github.com/codespell-project/codespell rev: v2.2.4 diff --git a/pyscript.core/src/core.css b/pyscript.core/src/core.css index c1a3dae9..73220a9a 100644 --- a/pyscript.core/src/core.css +++ b/pyscript.core/src/core.css @@ -1,4 +1,6 @@ py-script, -py-config { +py-config, +mpy-script, +mpy-config { display: none; } diff --git a/pyscript.core/src/core.js b/pyscript.core/src/core.js index 8ad0c78e..64ca230e 100644 --- a/pyscript.core/src/core.js +++ b/pyscript.core/src/core.js @@ -15,16 +15,15 @@ import stdlib from "./stdlib.js"; import { config, plugins, error } from "./config.js"; import { robustFetch as fetch, getText } from "./fetch.js"; -const { assign, defineProperty, entries } = Object; - -const TYPE = "py"; +const { assign, defineProperty } = Object; // allows lazy element features on code evaluation let currentElement; -// create a unique identifier when/if needed -let id = 0; -const getID = (prefix = TYPE) => `${prefix}-${id++}`; +const TYPES = new Map([ + ["py", "pyodide"], + ["mpy", "micropython"], +]); // generic helper to disambiguate between custom element and script const isScript = ({ tagName }) => tagName === "SCRIPT"; @@ -41,35 +40,11 @@ const after = () => { delete document.currentScript; }; -/** - * Given a generic DOM Element, tries to fetch the 'src' attribute, if present. - * It either throws an error if the 'src' can't be fetched or it returns a fallback - * content as source. - */ -const fetchSource = async (tag, io, asText) => { - if (tag.hasAttribute("src")) { - try { - return await fetch(tag.getAttribute("src")).then(getText); - } catch (error) { - io.stderr(error); - } - } - - if (asText) return dedent(tag.textContent); - - console.warn( - `Deprecated: use + + + +
+ +