Skip to content

Commit 7ad7f0a

Browse files
Fix pyscript#1943 - Updated Polyscript with configURL (pyscript#1944)
1 parent 1efd73a commit 7ad7f0a

File tree

8 files changed

+232
-181
lines changed

8 files changed

+232
-181
lines changed

pyscript.core/package-lock.json

Lines changed: 189 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyscript.core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.3.16",
3+
"version": "0.3.17",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",
@@ -42,7 +42,7 @@
4242
"dependencies": {
4343
"@ungap/with-resolvers": "^0.1.0",
4444
"basic-devtools": "^0.1.6",
45-
"polyscript": "^0.6.11",
45+
"polyscript": "^0.6.13",
4646
"sticky-module": "^0.1.1",
4747
"to-json-callback": "^0.1.1",
4848
"type-checked-collections": "^0.1.7"
@@ -53,7 +53,7 @@
5353
"@codemirror/language": "^6.10.0",
5454
"@codemirror/state": "^6.4.0",
5555
"@codemirror/view": "^6.23.0",
56-
"@playwright/test": "^1.40.1",
56+
"@playwright/test": "^1.41.0",
5757
"@rollup/plugin-commonjs": "^25.0.7",
5858
"@rollup/plugin-node-resolve": "^15.2.3",
5959
"@rollup/plugin-terser": "^0.4.4",

pyscript.core/src/config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ for (const [TYPE] of TYPES) {
6363
/** @type {Error | undefined} The error thrown when parsing the PyScript config, if any.*/
6464
let error;
6565

66+
/** @type {string | undefined} The `configURL` field to normalize all config operations as opposite of guessing it once resolved */
67+
let configURL;
68+
6669
let config,
6770
type,
6871
pyElement,
@@ -105,6 +108,7 @@ for (const [TYPE] of TYPES) {
105108
if (!error && config) {
106109
try {
107110
const { json, toml, text, url } = await configDetails(config, type);
111+
if (url) configURL = new URL(url, location.href).href;
108112
config = text;
109113
if (json || type === "json") {
110114
try {
@@ -146,7 +150,7 @@ for (const [TYPE] of TYPES) {
146150
// assign plugins as Promise.all only if needed
147151
plugins = Promise.all(toBeAwaited);
148152

149-
configs.set(TYPE, { config: parsed, plugins, error });
153+
configs.set(TYPE, { config: parsed, configURL, plugins, error });
150154
}
151155

152156
export default configs;

pyscript.core/src/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ for (const [TYPE, interpreter] of TYPES) {
6464
else dispatch(element, TYPE, "done");
6565
};
6666

67-
const { config, plugins, error } = configs.get(TYPE);
67+
const { config, configURL, plugins, error } = configs.get(TYPE);
6868

6969
// create a unique identifier when/if needed
7070
let id = 0;
@@ -259,6 +259,7 @@ for (const [TYPE, interpreter] of TYPES) {
259259

260260
define(TYPE, {
261261
config,
262+
configURL,
262263
interpreter,
263264
hooks,
264265
env: `${TYPE}-script`,

pyscript.core/test/config-url.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
<title>PyScript Next Plugin</title>
77
<link rel="stylesheet" href="../dist/core.css">
88
<script type="module" src="../dist/core.js"></script>
9-
<py-config src="bad.toml" type="toml"></py-config>
9+
<mpy-config src="config-url/config.json"></mpy-config>
10+
<script type="mpy">
11+
from runtime import test
12+
</script>
13+
<script type="mpy" worker>
14+
from runtime import test
15+
</script>
1016
</head>
1117
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files":{
3+
"{FROM}": "./src",
4+
"{TO}": "./runtime",
5+
"{FROM}/test.py": "{TO}/test.py"
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pyscript import RUNNING_IN_WORKER, document
2+
3+
classList = document.documentElement.classList
4+
5+
if RUNNING_IN_WORKER:
6+
classList.add("worker")
7+
else:
8+
classList.add("main")

pyscript.core/test/mpy.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,14 @@ test('MicroPython + Pyodide js_modules', async ({ page }) => {
5151
await expect(logs[3]).toBe(logs[4]);
5252
await expect(logs[4]).toBe(logs[5]);
5353
});
54+
55+
test('MicroPython + configURL', async ({ page }) => {
56+
const logs = [];
57+
page.on('console', msg => {
58+
const text = msg.text();
59+
if (!text.startsWith('['))
60+
logs.push(text);
61+
});
62+
await page.goto('http://localhost:8080/test/config-url.html');
63+
await page.waitForSelector('html.main.worker');
64+
});

0 commit comments

Comments
 (0)