Skip to content

Commit 088bff8

Browse files
committed
warn instead of error for pinned versions
1 parent df793d1 commit 088bff8

File tree

7 files changed

+67
-28
lines changed

7 files changed

+67
-28
lines changed

docs/index.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/index.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/interpreter/pyodide.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const type = 'pyodide';
88
const toJsOptions = { dict_converter: Object.fromEntries };
99

1010
const { stringify } = JSON;
11-
const { hasOwn } = Object;
11+
const { hasOwn, keys } = Object;
1212

1313
const { apply } = Reflect;
1414
const FunctionPrototype = Function.prototype;
@@ -66,6 +66,8 @@ const override = intercept => {
6666
});
6767
};
6868

69+
const warnOnPackageVersion = (version, name, value) => console.warn(`Pyodide ${version} might not support package ${name} version ${value}`);
70+
6971
const progress = createProgress('py');
7072
const indexURLs = new WeakMap();
7173

@@ -88,8 +90,29 @@ export default {
8890
if (/^https?:\/\//.test(entry)) return false;
8991
const [name, ...rest] = entry.split(/[>=<]=/);
9092
const known = hasOwn(graph[version], name);
91-
return !known || (rest.length > 0 && rest[0] !== graph[version][name]);
93+
if (!known) {
94+
// check if the package is available in the graph
95+
// with a different version that could work: warning only
96+
for (const key of keys(graph)) {
97+
if (key !== version && hasOwn(graph[key], name)) {
98+
warnOnPackageVersion(version, name, rest.at(0) ?? graph[key][name]);
99+
return false;
100+
}
101+
}
102+
// package not available in the graph with any version: error
103+
return true;
104+
}
105+
// warn if the pinned version is different from the one in the graph
106+
if (rest.length > 0 && rest[0] !== graph[version][name]) {
107+
warnOnPackageVersion(version, name, rest[0]);
108+
}
109+
// if known and pinned? it's considered valid
110+
return false;
92111
});
112+
113+
// invalid packages should not be allowed though
114+
// use a different index_url if needed because Pyodide
115+
// clearly never stated such package could work
93116
if (invalid.length > 0) {
94117
throw new Error(
95118
`These packages are not supported in Pyodide ${version}: ${invalid.join(', ')}`

package-lock.json

Lines changed: 22 additions & 22 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
@@ -53,7 +53,7 @@
5353
"@zip.js/zip.js": "^2.8.8",
5454
"c8": "^10.1.3",
5555
"chokidar": "^4.0.3",
56-
"eslint": "^9.38.0",
56+
"eslint": "^9.39.1",
5757
"linkedom": "^0.18.12",
5858
"rollup": "^4.52.5",
5959
"static-handler": "^0.5.3",
@@ -95,6 +95,6 @@
9595
"to-json-callback": "^0.1.1"
9696
},
9797
"worker": {
98-
"blob": "sha256-Epkjn7aMtcD7+5b5zqBH2CMgCLalXtFSWfuOZ7eOVCg="
98+
"blob": "sha256-lqTEoZcle8/LL85zi+N9VbMxe3g75m8m/cQ+pT+a0nI="
9999
}
100100
}

test/pygame-ce/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages = ["pygame-ce==2.4.1"]

test/pygame-ce/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>PyScript 0.28 warning on pygame-ce</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width,initial-scale=1">
7+
<script type="module" src="../../dist/index.js"></script>
8+
</head>
9+
<body>
10+
<script type="pyodide" version="0.28.0" config="config.toml">
11+
from js import document
12+
document.body.append("OK")
13+
</script>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)