Skip to content

Commit

Permalink
Add index_urls parsing for Pyodide
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Oct 29, 2024
1 parent 4a9e039 commit 93eaf50
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
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.

5 changes: 4 additions & 1 deletion esm/interpreter/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const applyOverride = () => {
};

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

export default {
type,
Expand All @@ -88,7 +89,7 @@ export default {
if (!RUNNING_IN_WORKER && config.experimental_create_proxy === 'auto')
applyOverride();
progress('Loading Pyodide');
let { packages } = config;
let { packages, index_urls } = config;
progress('Loading Storage');
const indexURL = url.slice(0, url.lastIndexOf('/'));
// each pyodide version shares its own cache
Expand Down Expand Up @@ -123,6 +124,7 @@ export default {
loadPyodide({ stderr, stdout, ...options }),
);
const py_imports = importPackages.bind(interpreter);
if (index_urls) indexURLs.set(interpreter, index_urls);
loader.set(interpreter, py_imports);
await loadProgress(this, progress, interpreter, config, baseURL);
// if cache wasn't know, import and freeze it for the next time
Expand Down Expand Up @@ -176,6 +178,7 @@ async function importPackages(packages, storage, save = false) {
console.log = _log;
await this.loadPackage('micropip');
const micropip = this.pyimport('micropip');
if (indexURLs.has(this)) micropip.set_index_urls(indexURLs.get(this));
await micropip.install(packages, { keep_going: true });
console.log = log;
if (save && (storage instanceof IDBMapSync)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@
"to-json-callback": "^0.1.1"
},
"worker": {
"blob": "sha256-52erKRHjBwcn2bnRpQFvjQxkigDMnQm/sOQdyX/Bc08="
"blob": "sha256-VuMxjAe+v4jsX88gfmCrUHme7CVnlZ36Y8U7l5uhDUU="
}
}
2 changes: 1 addition & 1 deletion test/integration.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>polyscript integration tests</title>
</head>
<body><ul><li><strong>micropython</strong><ul><li><a href="/test/integration/interpreter/micropython/bootstrap.html">bootstrap</a></li><li><a href="/test/integration/interpreter/micropython/config-json.html">config-json</a></li><li><a href="/test/integration/interpreter/micropython/config-object.html">config-object</a></li><li><a href="/test/integration/interpreter/micropython/current-script.html">current-script</a></li><li><a href="/test/integration/interpreter/micropython/custom-hooks.html">custom-hooks</a></li><li><a href="/test/integration/interpreter/micropython/fetch.html">fetch</a></li><li><a href="/test/integration/interpreter/micropython/interpreter-local.html">interpreter-local</a></li><li><a href="/test/integration/interpreter/micropython/mip.html">mip</a></li><li><a href="/test/integration/interpreter/micropython/no-type.html">no-type</a></li><li><a href="/test/integration/interpreter/micropython/ready-done.html">ready-done</a></li><li><a href="/test/integration/interpreter/micropython/storage.html">storage</a></li><li><a href="/test/integration/interpreter/micropython/worker-attribute.html">worker-attribute</a></li><li><a href="/test/integration/interpreter/micropython/worker-bad.html">worker-bad</a></li><li><a href="/test/integration/interpreter/micropython/worker-empty-attribute.html">worker-empty-attribute</a></li><li><a href="/test/integration/interpreter/micropython/worker-error.html">worker-error</a></li><li><a href="/test/integration/interpreter/micropython/worker-lua.html">worker-lua</a></li><li><a href="/test/integration/interpreter/micropython/worker-tag.html">worker-tag</a></li><li><a href="/test/integration/interpreter/micropython/worker-window.html">worker-window</a></li><li><a href="/test/integration/interpreter/micropython/worker.html">worker</a></li><li><a href="/test/integration/interpreter/micropython/workers.html">workers</a></li></ul><li><strong>pyodide</strong><ul><li><a href="/test/integration/interpreter/pyodide/bootstrap.html">bootstrap</a></li><li><a href="/test/integration/interpreter/pyodide/button.html">button</a></li><li><a href="/test/integration/interpreter/pyodide/config-json.html">config-json</a></li><li><a href="/test/integration/interpreter/pyodide/fetch.html">fetch</a></li><li><a href="/test/integration/interpreter/pyodide/sync.html">sync</a></li><li><a href="/test/integration/interpreter/pyodide/worker-error.html">worker-error</a></li><li><a href="/test/integration/interpreter/pyodide/worker-transform.html">worker-transform</a></li><li><a href="/test/integration/interpreter/pyodide/worker.html">worker</a></li></ul><li><strong>ruby-wasm-wasi</strong><ul><li><a href="/test/integration/interpreter/ruby-wasm-wasi/bootstrap.html">bootstrap</a></li></ul><li><strong>wasmoon</strong><ul><li><a href="/test/integration/interpreter/wasmoon/bootstrap.html">bootstrap</a></li><li><a href="/test/integration/interpreter/wasmoon/worker.html">worker</a></li></ul><li><strong>webr</strong><ul><li><a href="/test/integration/interpreter/webr/just-click.html">just-click</a></li></ul></ul></body>
<body><ul><li><strong>micropython</strong><ul><li><a href="/test/integration/interpreter/micropython/bootstrap.html">bootstrap</a></li><li><a href="/test/integration/interpreter/micropython/config-json.html">config-json</a></li><li><a href="/test/integration/interpreter/micropython/config-object.html">config-object</a></li><li><a href="/test/integration/interpreter/micropython/current-script.html">current-script</a></li><li><a href="/test/integration/interpreter/micropython/custom-hooks.html">custom-hooks</a></li><li><a href="/test/integration/interpreter/micropython/fetch.html">fetch</a></li><li><a href="/test/integration/interpreter/micropython/interpreter-local.html">interpreter-local</a></li><li><a href="/test/integration/interpreter/micropython/mip.html">mip</a></li><li><a href="/test/integration/interpreter/micropython/no-type.html">no-type</a></li><li><a href="/test/integration/interpreter/micropython/ready-done.html">ready-done</a></li><li><a href="/test/integration/interpreter/micropython/storage.html">storage</a></li><li><a href="/test/integration/interpreter/micropython/worker-attribute.html">worker-attribute</a></li><li><a href="/test/integration/interpreter/micropython/worker-bad.html">worker-bad</a></li><li><a href="/test/integration/interpreter/micropython/worker-empty-attribute.html">worker-empty-attribute</a></li><li><a href="/test/integration/interpreter/micropython/worker-error.html">worker-error</a></li><li><a href="/test/integration/interpreter/micropython/worker-lua.html">worker-lua</a></li><li><a href="/test/integration/interpreter/micropython/worker-tag.html">worker-tag</a></li><li><a href="/test/integration/interpreter/micropython/worker-window.html">worker-window</a></li><li><a href="/test/integration/interpreter/micropython/worker.html">worker</a></li><li><a href="/test/integration/interpreter/micropython/workers.html">workers</a></li></ul><li><strong>pyodide</strong><ul><li><a href="/test/integration/interpreter/pyodide/bootstrap.html">bootstrap</a></li><li><a href="/test/integration/interpreter/pyodide/button.html">button</a></li><li><a href="/test/integration/interpreter/pyodide/config-json.html">config-json</a></li><li><a href="/test/integration/interpreter/pyodide/fetch.html">fetch</a></li><li><a href="/test/integration/interpreter/pyodide/index_urls.html">index_urls</a></li><li><a href="/test/integration/interpreter/pyodide/sync.html">sync</a></li><li><a href="/test/integration/interpreter/pyodide/worker-error.html">worker-error</a></li><li><a href="/test/integration/interpreter/pyodide/worker-transform.html">worker-transform</a></li><li><a href="/test/integration/interpreter/pyodide/worker.html">worker</a></li></ul><li><strong>ruby-wasm-wasi</strong><ul><li><a href="/test/integration/interpreter/ruby-wasm-wasi/bootstrap.html">bootstrap</a></li></ul><li><strong>wasmoon</strong><ul><li><a href="/test/integration/interpreter/wasmoon/bootstrap.html">bootstrap</a></li><li><a href="/test/integration/interpreter/wasmoon/worker.html">worker</a></li></ul><li><strong>webr</strong><ul><li><a href="/test/integration/interpreter/webr/just-click.html">just-click</a></li></ul></ul></body>
</html>
18 changes: 18 additions & 0 deletions test/integration/interpreter/pyodide/index_urls.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module">
import { init } from '../utils.js';
init('pyodide');
</script>
</head>
<body>
<script type="pyodide" config='{"packages":["test_foo"],"index_urls":["https://test.pypi.org/simple"]}'>
import js
import test_foo
js.document.documentElement.classList.add(test_foo.__name__)
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions test/integration/pyodide.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export default (playwright, baseURL) => {
test('Pyodide transform', python.error(playwright, baseURL));

test('Pyodide events ready', python.disabledUntilReady(playwright, baseURL));

test('Pyodide index_urls', async ({ page }) => {
await page.goto(`${baseURL}/index_urls.html`);
await page.waitForSelector('html.test_foo');
});
};

0 comments on commit 93eaf50

Please sign in to comment.