Skip to content

Commit 474705e

Browse files
Merge pull request #42 from pyscript/issue-34
Fix #34 - Allow config to be an object
2 parents 16b13ce + 310455a commit 474705e

File tree

7 files changed

+62
-10
lines changed

7 files changed

+62
-10
lines changed

core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/loader.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { getJSON, getText } from './fetch-utils.js';
66
export const getConfigURLAndType = config => {
77
// REQUIRES INTEGRATION TEST
88
/* c8 ignore start */
9-
let type = '';
10-
if (/\.(json|toml|txt)$/.test(config))
9+
let type = typeof config;
10+
if (type === 'string' && /\.(json|toml|txt)$/.test(config))
1111
type = RegExp.$1;
1212
else
1313
config = './config.txt';
@@ -34,12 +34,14 @@ export const getRuntime = (id, config, options = {}) => {
3434
options = fetch(absolute).then(getJSON);
3535
} else if (type === 'toml') {
3636
options = fetch(absolute).then(getText).then(parse);
37-
} else if (!type) {
37+
} else if (type === 'string') {
3838
try {
3939
options = JSON.parse(config);
4040
} catch (_) {
4141
options = parse(config);
4242
}
43+
} else if (type === 'object' && config) {
44+
options = config;
4345
}
4446
config = absolute;
4547
/* c8 ignore stop */

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polyscript",
3-
"version": "0.3.9",
3+
"version": "0.3.10",
44
"description": "PyScript single core to rule them all",
55
"main": "./cjs/index.js",
66
"types": "./types/polyscript/esm/index.d.ts",
@@ -70,6 +70,6 @@
7070
"coincident": "^0.11.6"
7171
},
7272
"worker": {
73-
"blob": "sha256-su+ZGyxquPydhkn09WaMjWjvNQcTNH1HlrJpOs5r7K0="
73+
"blob": "sha256-1DM1q+m8AQYdQnBem2ugixNUGX1u/ZO0A7a+evjdrIg="
7474
}
7575
}

test/custom.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<style>
7+
mpy-script { display: none; }
8+
script-mpy { display: block; }
9+
</style>
10+
<script type="module">
11+
import { define } from '/core.js';
12+
const config = {
13+
fetch: [
14+
{ files: ["./a.py", "./b.py"] }
15+
]
16+
};
17+
define('mpy', {
18+
config,
19+
interpreter: 'micropython',
20+
onInterpreterReady(wrap, element) {
21+
console.assert(
22+
JSON.stringify(wrap.config) === JSON.stringify(config),
23+
'not the same config'
24+
);
25+
wrap.run(element.textContent);
26+
}
27+
});
28+
</script>
29+
</head>
30+
<body>
31+
<script type="mpy">
32+
print("main")
33+
import a
34+
from b import x
35+
print(x)
36+
</script>
37+
<script type="mpy" worker>
38+
print("worker")
39+
import a
40+
from b import x
41+
print(x)
42+
</script>
43+
<script type="mpy" worker config="./config.json">
44+
try:
45+
import a
46+
except:
47+
print("all good")
48+
</script>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)