8000 [pre-commit.ci] auto fixes from pre-commit.com hooks · pyscript/pyscript@b5a1161 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5a1161

Browse files
pre-commit-ci[bot]WebReflection
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent df48299 commit b5a1161

File tree

10 files changed

+248
-141
lines changed

10 files changed

+248
-141
lines changed

pyscript.core/package-lock.json

Lines changed: 134 additions & 134 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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.4.56",
3+
"version": "0.5.0",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"@ungap/with-resolvers": "^0.1.0",
4646
"basic-devtools": "^0.1.6",
47-
"polyscript": "^0.14.0-rc1",
47+
"polyscript": "^0.14.1",
4848
"sticky-module": "^0.1.1",
4949
"to-json-callback": "^0.1.1",
5050
"type-checked-collections": "^0.1.7"
@@ -54,20 +54,20 @@
5454
"@codemirror/lang-python": "^6.1.6",
5555
"@codemirror/language": "^6.10.2",
5656
"@codemirror/state": "^6.4.1",
57-
"@codemirror/view": "^6.28.6",
57+
"@codemirror/view": "^6.29.0",
5858
"@playwright/test": "^1.45.3",
5959
"@rollup/plugin-commonjs": "^26.0.1",
6060
"@rollup/plugin-node-resolve": "^15.2.3",
6161
"@rollup/plugin-terser": "^0.4.4",
6262
"@webreflection/toml-j0.4": "^1.1.3",
6363
"@xterm/addon-fit": "^0.10.0",
6464
"@xterm/addon-web-links": "^0.11.0",
65-
"bun": "^1.1.20",
65+
"bun": "^1.1.21",
6666
"chokidar": "^3.6.0",
6767
"codemirror": "^6.0.1",
68-
"eslint": "^9.7.0",
68+
"eslint": "^9.8.0",
6969
"flatted": "^3.3.1",
70-
"rollup": "^4.19.0",
70+
"rollup": "^4.19.1",
7171
"rollup-plugin-postcss": "^4.0.2",
7272
"rollup-plugin-string": "^3.0.0",
7373
"static-handler": "^0.4.3",

pyscript.core/src/plugins/py-editor.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ async function execute({ currentTarget }) {
3434

3535
if (!envs.has(env)) {
3636
const srcLink = URL.createObjectURL(new Blob([""]));
37-
const details = { type: this.interpreter };
37+
const details = {
38+
type: this.interpreter,
39+
serviceWorker: this.serviceWorker,
40+
};
3841
const { config } = this;
3942
if (config) {
4043
details.configURL = relative_url(config);
@@ -163,8 +166,18 @@ const init = async (script, type, interpreter) => {
163166

164167
let isSetup = script.hasAttribute("setup");
165168
const hasConfig = script.hasAttribute("config");
169+
const serviceWorker = script.getAttribute("service-worker");
166170
const env = `${interpreter}-${script.getAttribute("env") || getID(type)}`;
167171

172+
// helps preventing too lazy ServiceWorker initialization on button run
173+
if (serviceWorker) {
174+
const bootstrap = document.createElement('script');
175+
bootstrap.type = 'mpy';
176+
bootstrap.setAttribute('worker', '');
177+
bootstrap.setAttribute('service-worker', serviceWorker);
178+
document.head.appendChild(bootstrap);
179+
}
180+
168181
if (hasConfig && configs.has(env)) {
169182
throw new SyntaxError(
170183
configs.get(env)
@@ -181,6 +194,7 @@ const init = async (script, type, interpreter) => {
181194
const context = {
182195
// allow the listener to be overridden at distance
183196
handleEvent: execute,
197+
serviceWorker,
184198
interpreter,
185199
env,
186200
config: hasConfig && script.getAttribute("config"),

pyscript.core/src/stdlib/pyscript/magic_js.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __getattr__(self, field):
3737

3838
try:
3939
import js
40+
4041
window = polyscript.xworker.window
4142
document = window.document
4243
js.document = document
@@ -49,6 +50,7 @@ def __getattr__(self, field):
4950
globalThis.console.warn(message)
5051
window = NotSupported("pyscript.window", message)
5152
document = NotSupported("pyscript.document", message)
53+
js_import = None
5254

5355
sync = polyscript.xworker.sync
5456

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<link rel="stylesheet" href="../../dist/core.css">
7+
<script type="module" src="../../dist/core.js"></script>
8+
</head>
9+
<body>
10+
<script type="mpy-editor" service-worker="./sw.js">
11+
from pyscript import document
12+
13+
document.body.append("OK")
14+
</script>
15+
</body>
16+
</html>

pyscript.core/test/py-editor/sw.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Service Worker</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width,initial-scale=1">
7+
<link rel="stylesheet" href="../../dist/core.css">
8+
<script type="module" src="../../dist/core.js"></script>
9+
</head>
10+
<body>
11+
<script type="mpy" service-worker="./sabayon.js" worker>
12+
from pyscript import document
13+
document.body.append('OK')
14+
</script>
15+
</body>
16+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
2+
/*! mini-coi - Andrea Giammarchi and contributors, licensed under MIT */
3+
(({ document: d, navigator: { serviceWorker: s } }) => {
4+
if (d) {
5+
const { currentScript: c } = d;
6+
s.register(c.src, { scope: c.getAttribute('scope') || '.' }).then(r => {
7+
r.addEventListener('updatefound', () => location.reload());
8+
if (r.active && !s.controller) location.reload();
9+
});
10+
}
11+
else {
12+
addEventListener('install', () => skipWaiting());
13+
addEventListener('activate', e => e.waitUntil(clients.claim()));
14+
addEventListener('fetch', e => {
15+
const { request: r } = e;
16+
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
17+
e.respondWith(fetch(r).then(r => {
18+
const { body, status, statusText } = r;
19+
if (!status || status > 399) return r;
20+
const h = new Headers(r.headers);
21+
h.set('Cross-Origin-Opener-Policy', 'same-origin');
22+
h.set('Cross-Origin-Embedder-Policy', 'require-corp');
23+
h.set('Cross-Origin-Resource-Policy', 'cross-origin');
24+
return new Response(body, { status, statusText, headers: h });
25+
}));
26+
});
27+
}
28+
})(self);

pyscript.core/test/service-worker/sabayon.js

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

pyscript.core/test/workers/named.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<title>named workers</title>
7+
<script type="module" src="../../dist/core.js"></script>
8+
</head>
9+
<body>
10+
<script type="mpy" async>
11+
from pyscript import workers
12+
13+
await (await workers["mpy"]).greetings()
14+
await (await workers["py"]).greetings()
15+
</script>
16+
<script type="mpy" worker name="mpy">
17+
def greetings():
18+
print("micropython")
19+
20+
__export__ = ['greetings']
21+
</script>
22+
<script type="py" worker name="py">
23+
def greetings():
24+
print("pyodide")
25+
26+
__export__ = ['greetings']
27+
</script>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)
0