Skip to content
Merged
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
9 changes: 7 additions & 2 deletions ui/lib/pyodide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

const PYODIDE_VERSION = "0.29.3";
const PYODIDE_INDEX_URL = `https://cdn.jsdelivr.net/pyodide/v${PYODIDE_VERSION}/full/`;
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? "";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Pyodide = any;

let _instance: Pyodide | null = null;
let _promise: Promise<Pyodide> | null = null;

function withBasePath(path: string) {
return `${BASE_PATH}${path}`;
}

function injectScript(src: string): Promise<void> {
return new Promise((resolve, reject) => {
if (document.querySelector(`script[src="${src}"]`)) {
Expand Down Expand Up @@ -43,8 +48,8 @@ export function getPyodide(): Promise<Pyodide> {
await pyodide.loadPackage(["numpy", "micropip"]);

// Fetch manifest written by prebuild.mjs to get the versioned wheel filename
const { wheel } = await fetch("/_pkg/manifest.json").then((r) => r.json());
const wheelUrl = `${window.location.origin}/_pkg/${wheel}`;
const { wheel } = await fetch(withBasePath("/_pkg/manifest.json")).then((r) => r.json());
const wheelUrl = new URL(withBasePath(`/_pkg/${wheel}`), window.location.origin).toString();
await pyodide.runPythonAsync(`
import micropip
await micropip.install("${wheelUrl}")
Expand Down
Loading