Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

pyodide: lazily install black on first format (#894)

Akshay Agrawal0622da368ac1
diff --git a/frontend/src/core/pyodide/worker/bootstrap.ts b/frontend/src/core/pyodide/worker/bootstrap.ts
index ace832ceda..c8d0fc29a0 100644
--- a/frontend/src/core/pyodide/worker/bootstrap.ts
+++ b/frontend/src/core/pyodide/worker/bootstrap.ts
@@ -31,7 +31,7 @@ export async function bootstrap() {
const marimoWheel =
process.env.NODE_ENV === "production"
? "marimo >= 0.2.5"
- : "http://localhost:8000/dist/marimo-0.2.10-py3-none-any.whl";
+ : "http://localhost:8000/dist/marimo-0.2.13-py3-none-any.whl";
await pyodide.runPythonAsync(`
import micropip
diff --git a/frontend/src/core/pyodide/worker/worker.ts b/frontend/src/core/pyodide/worker/worker.ts
index 5f04d757d4..5de5efcb8a 100644
--- a/frontend/src/core/pyodide/worker/worker.ts
+++ b/frontend/src/core/pyodide/worker/worker.ts
@@ -93,6 +93,19 @@ self.onmessage = async (event: MessageEvent<WorkerServerPayload>) => {
postMessage({ type: "response", response: file, id });
return;
}
+ // Special case to lazily install black on format
+ // Don't return early; still need to ask the pyodide kernel to run
+ // the formatter
+ if (functionName === "format") {
+ await self.pyodide.runPythonAsync(`
+ import micropip
+
+ try:
+ import black
+ except ModuleNotFoundError:
+ await micropip.install("black")
+ `);
+ }
// Perform the function call to the Python bridge
const bridge = await getBridge();