Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions esm/interpreter/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const type = 'pyodide';
const toJsOptions = { dict_converter: Object.fromEntries };

const { stringify } = JSON;
const { hasOwn } = Object;
const { hasOwn, keys } = Object;

const { apply } = Reflect;
const FunctionPrototype = Function.prototype;
Expand Down Expand Up @@ -66,6 +66,8 @@ const override = intercept => {
});
};

const warnOnPackageVersion = (version, name, value) => console.warn(`Pyodide ${version} might not support package ${name} version ${value}`);

const progress = createProgress('py');
const indexURLs = new WeakMap();

Expand All @@ -88,8 +90,29 @@ export default {
if (/^https?:\/\//.test(entry)) return false;
const [name, ...rest] = entry.split(/[>=<]=/);
const known = hasOwn(graph[version], name);
return !known || (rest.length > 0 && rest[0] !== graph[version][name]);
if (!known) {
// check if the package is available in the graph
// with a different version that could work: warning only
for (const key of keys(graph)) {
if (key !== version && hasOwn(graph[key], name)) {
warnOnPackageVersion(version, name, rest.at(0) ?? graph[key][name]);
return false;
}
}
// package not available in the graph with any version: error
return true;
}
// warn if the pinned version is different from the one in the graph
if (rest.length > 0 && rest[0] !== graph[version][name]) {
warnOnPackageVersion(version, name, rest[0]);
}
// if known and pinned? it's considered valid
return false;
});

// invalid packages should not be allowed though
// use a different index_url if needed because Pyodide
// clearly never stated such package could work
if (invalid.length > 0) {
throw new Error(
`These packages are not supported in Pyodide ${version}: ${invalid.join(', ')}`
Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@zip.js/zip.js": "^2.8.8",
"c8": "^10.1.3",
"chokidar": "^4.0.3",
"eslint": "^9.38.0",
"eslint": "^9.39.1",
"linkedom": "^0.18.12",
"rollup": "^4.52.5",
"static-handler": "^0.5.3",
Expand Down Expand Up @@ -95,6 +95,6 @@
"to-json-callback": "^0.1.1"
},
"worker": {
"blob": "sha256-Epkjn7aMtcD7+5b5zqBH2CMgCLalXtFSWfuOZ7eOVCg="
"blob": "sha256-lqTEoZcle8/LL85zi+N9VbMxe3g75m8m/cQ+pT+a0nI="
}
}
1 change: 1 addition & 0 deletions test/pygame-ce/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages = ["pygame-ce==2.4.1"]
15 changes: 15 additions & 0 deletions test/pygame-ce/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>PyScript 0.28 warning on pygame-ce</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="module" src="../../dist/index.js"></script>
</head>
<body>
<script type="pyodide" version="0.28.0" config="config.toml">
from js import document
document.body.append("OK")
</script>
</body>
</html>