Exposing config type once resolved and running (#2175)

This commit is contained in:
Andrea Giammarchi
2024-09-17 17:04:32 +02:00
committed by GitHub
parent 84c7d69db9
commit dd86169f2a
4 changed files with 34 additions and 1 deletions

View File

@@ -10,6 +10,11 @@ RUNNING_IN_WORKER = not hasattr(globalThis, "document")
config = json.loads(globalThis.JSON.stringify(_config))
if "MicroPython" in sys.version:
config["type"] = "mpy"
else:
config["type"] = "py"
# allow `from pyscript.js_modules.xxx import yyy`
class JSModule:

File diff suppressed because one or more lines are too long

View File

@@ -114,3 +114,8 @@ test('Pyodide loader', async ({ page }) => {
const body = await page.evaluate(() => document.body.textContent);
await expect(body.includes('Loaded Pyodide')).toBe(true);
});
test('Py and Mpy config["type"]', async ({ page }) => {
await page.goto('http://localhost:8080/tests/js-integration/config_type.html');
await page.waitForSelector('html.mpy.py');
});

View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../../dist/core.css">
<script type="module" src="../../dist/core.js"></script>
</head>
<body>
<script type="mpy">
from pyscript import config, document
if config["type"] is "mpy":
document.documentElement.classList.add("mpy")
</script>
<script type="py">
from pyscript import config, document
if config["type"] is "py":
document.documentElement.classList.add("py")
</script>
</body>
</html>