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.

chore: upgrade pyodide to 0.27.0 (#3360)

Myles Scolnick79717dbd058f
diff --git a/frontend/package.json b/frontend/package.json
index 255f3e3112..72bd27891c 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -114,7 +114,7 @@
"partysocket": "1.0.2",
"path-to-regexp": "^8.0.0",
"plotly.js": "^2.35.2",
- "pyodide": "^0.26.2",
+ "pyodide": "^0.27.0",
"react-arborist": "^3.4.0",
"react-aria-components": "^1.5.0",
"react-codemirror-merge": "^4.23.5",
@@ -189,7 +189,6 @@
"@swc-jotai/react-refresh": "^0.1.1",
"@testing-library/react": "^16.0.0",
"@testing-library/react-hooks": "^8.0.1",
- "@types/emscripten": "^1.39.13",
"@types/katex": "^0.16.7",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.16.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index ee8964a40c..c432fb1aff 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -319,8 +319,8 @@ importers:
specifier: ^2.35.2
pyodide:
- specifier: ^0.26.2
- version: 0.26.2
+ specifier: ^0.27.0
+ version: 0.27.0
react-arborist:
specifier: ^3.4.0
@@ -463,9 +463,6 @@ importers:
'@testing-library/react-hooks':
specifier: ^8.0.1
- '@types/emscripten':
- specifier: ^1.39.13
- version: 1.39.13
'@types/katex':
specifier: ^0.16.7
version: 0.16.7
@@ -3493,9 +3490,6 @@ packages:
resolution: {integrity: sha512-eOIHzCUSH7SMfonMG1LsC2f8vxBFtho6NGBznK41R84YzPuvSBzrhEps33IsQiOW9+VL6NQ9DbjQJznk/S4uRA==}
- '@types/[email protected]':
- resolution: {integrity: sha512-cFq+fO/isvhvmuP/+Sl4K4jtU6E23DoivtbO4r50e3odaxAiVdbfSYRDdJ4gCdxx+3aRjhphS5ZMwIH4hFy/Cw==}
-
resolution: {integrity: sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==}
@@ -7349,8 +7343,8 @@ packages:
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
engines: {node: '>=6'}
- resolution: {integrity: sha512-8VCRdFX83gBsWs6XP2rhG8HMaB+JaVyyav4q/EMzoV8fXH8HN6T5IISC92SNma6i1DRA3SVXA61S1rJcB8efgA==}
+ resolution: {integrity: sha512-0O992noCKqv8lPw4+QFWw8d8yrNWVtQ6zPhWNg/RNYbFohiwmV6SGlVh5fWk/4pOxyhgHbayq+ur8JoR/r5U9A==}
engines: {node: '>=18.0.0'}
@@ -12876,8 +12870,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]': {}
-
dependencies:
'@types/eslint': 9.6.1
@@ -17416,7 +17408,7 @@ snapshots:
dependencies:
ws: 8.18.0
transitivePeerDependencies:
diff --git a/frontend/src/core/wasm/worker/fs.ts b/frontend/src/core/wasm/worker/fs.ts
index 60512a00b3..2d11cc4d75 100644
--- a/frontend/src/core/wasm/worker/fs.ts
+++ b/frontend/src/core/wasm/worker/fs.ts
@@ -1,6 +1,7 @@
/* Copyright 2024 Marimo. All rights reserved. */
import type { PyodideInterface } from "pyodide";
import { getFS } from "./getFS";
+import { decodeUtf8 } from "@/utils/strings";
const NOTEBOOK_FILENAME = "notebook.py";
const HOME_DIR = "/marimo";
@@ -12,7 +13,7 @@ export const WasmFileSystem = {
// Create and change to the home directory
const FS = getFS(pyodide);
try {
- FS.mkdir(HOME_DIR);
+ FS.mkdirTree(HOME_DIR);
} catch {
// Ignore if the directory already exists
}
@@ -32,19 +33,19 @@ export const WasmFileSystem = {
readNotebook: (pyodide: PyodideInterface) => {
const FS = getFS(pyodide);
const absPath = `${HOME_DIR}/${NOTEBOOK_FILENAME}`;
- return FS.readFile(absPath, { encoding: "utf8" });
+ return decodeUtf8(FS.readFile(absPath));
},
initNotebookCode: (opts: {
pyodide: PyodideInterface;
code: string;
filename: string | null;
- }) => {
+ }): { code: string; filename: string } => {
const { pyodide, filename, code } = opts;
const FS = getFS(pyodide);
- const readIfExist = (filename: string) => {
+ const readIfExist = (filename: string): string | null => {
try {
- return FS.readFile(filename, { encoding: "utf8" });
+ return decodeUtf8(FS.readFile(filename));
} catch {
return null;
}
@@ -78,8 +79,8 @@ function syncFileSystem(
// Sync the filesystem. This brings IndexedDBFS up to date with the in-memory filesystem
// `true` when starting up, `false` when shutting down
return new Promise<void>((resolve, reject) => {
- getFS(pyodide).syncfs(populate, (err: Error) => {
- if (err) {
+ getFS(pyodide).syncfs(populate, (err: unknown) => {
+ if (err instanceof Error) {
reject(err);
return;
}
diff --git a/frontend/src/core/wasm/worker/getFS.ts b/frontend/src/core/wasm/worker/getFS.ts
index 28364ce610..256bdaeb5a 100644
--- a/frontend/src/core/wasm/worker/getFS.ts
+++ b/frontend/src/core/wasm/worker/getFS.ts
@@ -4,6 +4,6 @@ import type { PyodideInterface } from "pyodide";
/**
* Wrapper around pyodide.FS to add type safety.
*/
-export function getFS(pyodide: PyodideInterface): typeof FS {
+export function getFS(pyodide: PyodideInterface): PyodideInterface["FS"] {
return pyodide.FS;
}
diff --git a/frontend/src/core/wasm/worker/save-worker.ts b/frontend/src/core/wasm/worker/save-worker.ts
index 37a2c010a7..29cb6e9a72 100644
--- a/frontend/src/core/wasm/worker/save-worker.ts
+++ b/frontend/src/core/wasm/worker/save-worker.ts
@@ -15,6 +15,7 @@ import { getPyodideVersion } from "./getPyodideVersion";
import type { SaveNotebookRequest } from "@/core/network/types";
import { WasmFileSystem } from "./fs";
import { getController } from "./getController";
+import { decodeUtf8 } from "@/utils/strings";
/**
* Web worker responsible for saving the notebook.
@@ -58,7 +59,7 @@ const pyodideReadyPromise = loadPyodideAndPackages();
const requestHandler = createRPCRequestHandler({
readFile: async (filename: string) => {
await pyodideReadyPromise; // Make sure loading is done
- const file = self.pyodide.FS.readFile(filename, { encoding: "utf8" });
+ const file = decodeUtf8(self.pyodide.FS.readFile(filename));
return file;
},
readNotebook: async () => {
diff --git a/frontend/src/core/wasm/worker/worker.ts b/frontend/src/core/wasm/worker/worker.ts
index 5d6825b80a..ff6b64d7d9 100644
--- a/frontend/src/core/wasm/worker/worker.ts
+++ b/frontend/src/core/wasm/worker/worker.ts
@@ -27,6 +27,7 @@ import type {
ListPackagesResponse,
PackageOperationResponse,
} from "@/core/network/types";
+import { decodeUtf8 } from "@/utils/strings";
/**
* Web worker responsible for running the notebook.
@@ -154,7 +155,7 @@ const requestHandler = createRPCRequestHandler({
const span = t.startSpan("readFile");
await pyodideReadyPromise; // Make sure loading is done
- const file = self.pyodide.FS.readFile(filename, { encoding: "utf8" });
+ const file = decodeUtf8(self.pyodide.FS.readFile(filename));
span.end();
return file;
},
diff --git a/frontend/src/utils/strings.ts b/frontend/src/utils/strings.ts
index 8a4a0628ed..fd11725f83 100644
--- a/frontend/src/utils/strings.ts
+++ b/frontend/src/utils/strings.ts
@@ -44,3 +44,8 @@ export const Strings = {
return url.startsWith("/") ? url.slice(1) : url;
},
};
+
+export const decodeUtf8 = (array: Uint8Array): string => {
+ const str = new TextDecoder().decode(array);
+ return str;
+};
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index d46fc594ba..a00af71de8 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -36,8 +36,7 @@
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
"types": [
- "vite/client",
- "@types/emscripten"
+ "vite/client"
] /* Specify type package names to be included without being referenced in a source file. */,
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */