Skip to content

Commit 2ae84fe

Browse files
committed
fix: always ensure micropip and ipython are loaded by loadPyodide
Instead of complex fallback mechanisms, guarantee that micropip and ipython are always included in the packages list passed to loadPyodide(), regardless of what custom package list is provided. This prevents CI failures due to missing packages while maintaining the optimized parallel loading approach. Removes complex fallback error handling since the packages will always be available from the initial load.
1 parent 84c38f7 commit 2ae84fe

File tree

1 file changed

+20
-58
lines changed

1 file changed

+20
-58
lines changed

packages/pyodide-runtime-agent/src/pyodide-worker.ts

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ async function initializePyodide(
6565

6666
// Get cache configuration and packages to load
6767
const { packageCacheDir } = getCacheConfig();
68-
const packagesForInit = packagesToLoad || getEssentialPackages();
68+
const basePackages = packagesToLoad || getEssentialPackages();
69+
70+
// Always ensure micropip and ipython are included for core functionality
71+
const packagesForInit = Array.from(
72+
new Set([
73+
"micropip",
74+
"ipython",
75+
...basePackages,
76+
]),
77+
);
6978

7079
self.postMessage({
7180
type: "log",
@@ -121,65 +130,18 @@ async function setupIPythonEnvironment(): Promise<void> {
121130
data: "Loading IPython environment from bootstrap file",
122131
});
123132

124-
try {
125-
// Get the Python bootstrap code
126-
const pythonBootstrap = await fetch(
127-
new URL("./ipython-setup.py", import.meta.url),
128-
).then((response) => response.text());
129-
130-
// Execute the bootstrap code
131-
await pyodide!.runPythonAsync(pythonBootstrap);
132-
133-
self.postMessage({
134-
type: "log",
135-
data: "IPython environment loaded successfully",
136-
});
137-
} catch (error) {
138-
// If IPython setup fails, try to install it as a fallback
139-
self.postMessage({
140-
type: "log",
141-
data: `IPython setup failed: ${error}, attempting fallback installation`,
142-
});
143-
144-
try {
145-
// First load micropip using pyodide.loadPackage
146-
self.postMessage({
147-
type: "log",
148-
data: "Loading micropip for fallback installation",
149-
});
150-
151-
await pyodide!.loadPackage(["micropip"]);
133+
// Get the Python bootstrap code
134+
const pythonBootstrap = await fetch(
135+
new URL("./ipython-setup.py", import.meta.url),
136+
).then((response) => response.text());
152137

153-
// Then use micropip to install IPython
154-
await pyodide!.runPythonAsync(`
155-
import micropip
156-
await micropip.install("ipython")
157-
`);
138+
// Execute the bootstrap code
139+
await pyodide!.runPythonAsync(pythonBootstrap);
158140

159-
self.postMessage({
160-
type: "log",
161-
data: "IPython installed via micropip fallback",
162-
});
163-
164-
// Retry the bootstrap setup
165-
const pythonBootstrap = await fetch(
166-
new URL("./ipython-setup.py", import.meta.url),
167-
).then((response) => response.text());
168-
169-
await pyodide!.runPythonAsync(pythonBootstrap);
170-
171-
self.postMessage({
172-
type: "log",
173-
data: "IPython environment loaded successfully after fallback",
174-
});
175-
} catch (fallbackError) {
176-
self.postMessage({
177-
type: "error",
178-
data: `Failed to set up IPython environment: ${fallbackError}`,
179-
});
180-
throw fallbackError;
181-
}
182-
}
141+
self.postMessage({
142+
type: "log",
143+
data: "IPython environment loaded successfully",
144+
});
183145
}
184146

185147
/**

0 commit comments

Comments
 (0)