Skip to content

Fix #137 - Allow the passthrough option for the cache #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
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.

3 changes: 3 additions & 0 deletions docs/toml-BK2RWy-G.js

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

1 change: 1 addition & 0 deletions docs/toml-BK2RWy-G.js.map

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

2 changes: 2 additions & 0 deletions docs/zip-BKVoQflw.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/zip-BKVoQflw.js.map

Large diffs are not rendered by default.

42 changes: 25 additions & 17 deletions esm/interpreter/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,45 @@ export default {
type,
module: (version = '0.27.7') =>
`https://cdn.jsdelivr.net/pyodide/v${version}/full/pyodide.mjs`,
async engine({ loadPyodide }, config, url, baseURL) {
async engine({ loadPyodide, version }, config, url, baseURL) {
progress('Loading Pyodide');
let { packages, index_urls } = config;
if (packages) packages = packages.map(fixedRelative, baseURL);
progress('Loading Storage');
const indexURL = url.slice(0, url.lastIndexOf('/'));
// each pyodide version shares its own cache
const storage = new IDBMapSync(indexURL);
const storage = new IDBMapSync(`${indexURL}@${version}`);
const options = { indexURL };
const save = config.packages_cache !== 'never';
await storage.sync();
// packages_cache = 'never' means: erase the whole DB
if (!save) storage.clear();
// otherwise check if cache is known
else if (packages) {
packages = packages.sort();
// packages are uniquely stored as JSON key
const key = stringify(packages);
if (storage.has(key)) {
const blob = new Blob(
[storage.get(key)],
{ type: 'application/json' },
);
// this should be used to bootstrap loadPyodide
options.lockFileURL = URL.createObjectURL(blob);
// versions are not currently understood by pyodide when
// a lockFileURL is used instead of micropip.install(packages)
// https://github.com/pyodide/pyodide/issues/5135#issuecomment-2441038644
// https://github.com/pyscript/pyscript/issues/2245
options.packages = packages.map(name => name.split(/[>=<]=/)[0]);
// packages_cache = 'passthrough' means: do not use micropip.install
if (config.packages_cache === 'passthrough') {
options.packages = packages;
packages = null;
storage.clear();
}
else {
packages = packages.sort();
// packages are uniquely stored as JSON key
const key = stringify(packages);
if (storage.has(key)) {
const blob = new Blob(
[storage.get(key)],
{ type: 'application/json' },
);
// this should be used to bootstrap loadPyodide
options.lockFileURL = URL.createObjectURL(blob);
// versions are not currently understood by pyodide when
// a lockFileURL is used instead of micropip.install(packages)
// https://github.com/pyodide/pyodide/issues/5135#issuecomment-2441038644
// https://github.com/pyscript/pyscript/issues/2245
options.packages = packages.map(name => name.split(/[>=<]=/)[0]);
packages = null;
}
}
}
progress('Loaded Storage');
Expand Down
Loading