-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: include local wheels in WASM exports #10071
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,10 +108,18 @@ export class DefaultWasmController implements WasmController { | |
| queryParameters: Record<string, string | string[]>; | ||
| code: string; | ||
| filename: string | null; | ||
| wheelUrls?: string[]; | ||
| onMessage: (message: JsonString<NotificationPayload>) => void; | ||
| userConfig: UserConfig; | ||
| }): Promise<SerializedBridge> { | ||
| const { code, filename, onMessage, queryParameters, userConfig } = opts; | ||
| const { | ||
| code, | ||
| filename, | ||
| onMessage, | ||
| queryParameters, | ||
| userConfig, | ||
| wheelUrls = [], | ||
| } = opts; | ||
| // We pass down a messenger object to the code | ||
| // This is used to have synchronous communication between the JS and Python code | ||
| // Previously, we used a queue, but this would not properly flush the queue | ||
|
|
@@ -124,6 +132,8 @@ export class DefaultWasmController implements WasmController { | |
| self.query_params = queryParameters; | ||
| self.user_config = userConfig; | ||
|
|
||
| await this.installIncludedWheels(wheelUrls); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Wheel URLs from Prompt for AI agents |
||
|
|
||
| const span = t.startSpan("startSession.runPython"); | ||
| const nbFilename = filename || WasmFileSystem.NOTEBOOK_FILENAME; | ||
| const [bridge, init, packages] = this.requirePyodide.runPython( | ||
|
|
@@ -169,6 +179,23 @@ export class DefaultWasmController implements WasmController { | |
| return bridge; | ||
| } | ||
|
|
||
| private async installIncludedWheels(wheelUrls: string[]) { | ||
| if (wheelUrls.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const loadSpan = t.startSpan("micropip.install.wheels"); | ||
| try { | ||
| await this.requirePyodide.runPythonAsync(` | ||
| import micropip | ||
| print("Loading included wheels:", ${JSON.stringify(wheelUrls)}) | ||
| await micropip.install(${JSON.stringify(wheelUrls)}) | ||
| `); | ||
| } finally { | ||
| loadSpan.end(); | ||
| } | ||
| } | ||
|
|
||
| private async loadNotebookDeps(code: string, foundPackages: Set<string>) { | ||
| const pyodide = this.requirePyodide; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1:
wasmWheelUrlsentries are only validated as plain strings inmount.tsx, so malformed or empty URL values can reachbridge.ts. InstartSession(),new URL(url, document.baseURI)is called for each entry without any guard, andnew URL()throws aTypeErroron invalid input. BecausestartSession()is async and thereadylistener calls it withoutawaitor.catch(), a single bad wheel URL produces an unhandled rejection that aborts the entire WASM session startup flow before the RPC call is even reached.Consider wrapping the URL parsing so invalid entries are logged and filtered out rather than crashing initialization. For example, using
flatMapwith atry/catchblock would let the session start with the valid URLs while surfacing the bad ones viaLogger.warn.Prompt for AI agents