Skip to content

Commit

Permalink
Fix URL rewriting in loadPyodideOptions (#105)
Browse files Browse the repository at this point in the history
* fix URL rewriting in loadPyodideOptions

* use native URL to resolve against baseUrl

* fix config typing
  • Loading branch information
bollwyvl committed Mar 30, 2024
1 parent bc3e803 commit 8c2c62a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/jupyter-lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"litePluginSettings": {
"@jupyterlite/pyodide-kernel-extension:kernel": {
"loadPyodideOptions": {
"packages": ["matplotlib", "micropip", "numpy", "sqlite3", "ssl"]
"packages": ["matplotlib", "micropip", "numpy", "sqlite3", "ssl"],
"lockFileURL": "https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide-lock.json?from-lite-config=1"
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/pyodide-kernel-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const kernel: JupyterLiteServerPlugin<void> = {
) => {
const config =
JSON.parse(PageConfig.getOption('litePluginSettings') || '{}')[PLUGIN_ID] || {};

const baseUrl = PageConfig.getBaseUrl();

const url = config.pyodideUrl || PYODIDE_CDN_URL;

const pyodideUrl = URLExt.parse(url).href;
Expand All @@ -56,7 +59,7 @@ const kernel: JupyterLiteServerPlugin<void> = {

for (const [key, value] of Object.entries(loadPyodideOptions)) {
if (key.endsWith('URL') && typeof value === 'string') {
loadPyodideOptions[key] = URLExt.parse(key).href;
loadPyodideOptions[key] = new URL(value, baseUrl).href;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/pyodide-kernel/src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export namespace PyodideKernel {
* @see https://pyodide.org/en/stable/usage/api/js-api.html#globalThis.loadPyodide
*/
loadPyodideOptions: Record<string, any> & {
pyodideLockURL: string;
lockFileURL: string;
packages: string[];
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pyodide-kernel/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export namespace IPyodideWorkerKernel {
* @see https://pyodide.org/en/stable/usage/api/js-api.html#globalThis.loadPyodide
*/
loadPyodideOptions: Record<string, any> & {
pyodideLockURL: string;
lockFileURL: string;
packages: string[];
};
}
Expand Down

0 comments on commit 8c2c62a

Please sign in to comment.