Skip to content

Commit 38540bf

Browse files
authored
Update Pyodide to 0.27.2 (#1300)
* Update Pyodide to 0.27.2 * Update Python to 3.12.7 * Type workaround * Fix wheel URLs resolution
1 parent 643ca87 commit 38540bf

13 files changed

+41
-31
lines changed

.python-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12.1
1+
3.12.7

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444
"immutable": "4.2.3",
4545
"protobufjs": "7.2.5",
4646
"@types/react": "^18.2.0"
47-
}
47+
},
48+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
4849
}

packages/desktop/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test": "vitest",
3030
"start:electron": "tsc -p electron && cross-env NODE_ENV=development concurrently \"./scripts/build_electron.js --watch\" \"electron .\"",
3131
"build:electron": "tsc -p electron && cross-env NODE_ENV=production ./scripts/build_electron.js",
32-
"build:pyodide": "curl -L https://github.com/pyodide/pyodide/releases/download/0.26.2/pyodide-core-0.26.2.tar.bz2 | tar xj -C ./build --files-from=./pyodide-files.txt",
32+
"build:pyodide": "curl -L https://github.com/pyodide/pyodide/releases/download/0.27.2/pyodide-core-0.27.2.tar.bz2 | tar xj -C ./build --files-from=./pyodide-files.txt",
3333
"build:bin": "tsc -p bin-src && ./scripts/build_bin.js",
3434
"build:wheels": "./scripts/copy_wheels.js",
3535
"postbuild:web": "./scripts/post_build_web.js",
@@ -58,7 +58,7 @@
5858
"//": "The packages not bundled with bin/dump_artifacts.js must be specified here as the runtime dependencies. See `scripts/build_bin.js` for the details.",
5959
"dependencies": {
6060
"fs-extra": "^11.2.0",
61-
"pyodide": "0.26.2",
61+
"pyodide": "0.27.2",
6262
"yargs": "^17.7.2"
6363
},
6464
"devDependencies": {

packages/kernel/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@types/path-browserify": "^1.0.0",
2525
"@types/react": "^18.2.0",
2626
"@vitejs/plugin-react": "^4.3.4",
27-
"pyodide": "0.26.2"
27+
"pyodide": "0.27.2"
2828
},
2929
"dependencies": {
3030
"@jupyterlab/coreutils": "^6.3.4",

packages/kernel/py/stlite-lib/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies = [
1515
dev-dependencies = [
1616
"matplotlib>=3.9.2",
1717
"pandas-stubs>=2.2.3.241009",
18-
"pyodide-py>=0.26.2",
18+
"pyodide-py>=0.27.2",
1919
"pyright>=1.1.384",
2020
"pytest>=8.3.3",
2121
"pytest-asyncio>=0.24.0",

packages/kernel/py/stlite-lib/uv.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/kernel/src/file.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { describe, it, expect, beforeEach } from "vitest";
55
import { writeFileWithParents, renameWithParents } from "./file";
66

77
describe("writeFileWithParents()", () => {
8-
let pyodide: PyodideInterface;
8+
let pyodide: PyodideInterface & { FS: any }; // XXX: This is a temporary workaround to fix the type error.
99

1010
beforeEach(async () => {
1111
pyodide = await loadPyodide({
@@ -45,7 +45,7 @@ describe("writeFileWithParents()", () => {
4545
});
4646

4747
describe("renameWithParents", () => {
48-
let pyodide: PyodideInterface;
48+
let pyodide: PyodideInterface & { FS: any }; // XXX: This is a temporary workaround to fix the type error.
4949

5050
beforeEach(async () => {
5151
pyodide = await loadPyodide({

packages/kernel/src/file.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export const resolveAppPath = (
1616
return path.resolve(getAppHomeDir(appId), filePath);
1717
};
1818

19-
function ensureParent(pyodide: PyodideInterface, filePath: string): void {
19+
function ensureParent(
20+
pyodide: PyodideInterface & { FS: any }, // XXX: This is a temporary workaround to fix the type error.
21+
filePath: string,
22+
): void {
2023
const normalized = path.normalize(filePath);
2124

2225
const dirPath = path.dirname(normalized);
@@ -45,17 +48,17 @@ function ensureParent(pyodide: PyodideInterface, filePath: string): void {
4548
}
4649

4750
export function writeFileWithParents(
48-
pyodide: PyodideInterface,
51+
pyodide: PyodideInterface & { FS: any }, // XXX: This is a temporary workaround to fix the type error.
4952
filePath: string,
5053
data: string | ArrayBufferView,
51-
opts?: Parameters<PyodideInterface["FS"]["writeFile"]>[2],
54+
opts?: unknown,
5255
): void {
5356
ensureParent(pyodide, filePath);
5457
pyodide.FS.writeFile(filePath, data, opts);
5558
}
5659

5760
export function renameWithParents(
58-
pyodide: PyodideInterface,
61+
pyodide: PyodideInterface & { FS: any }, // XXX: This is a temporary workaround to fix the type error.
5962
oldPath: string,
6063
newPath: string,
6164
): void {

packages/kernel/src/worker-runtime.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference lib="WebWorker" />
22

3-
import type Pyodide from "pyodide";
3+
import type { PyodideInterface } from "pyodide";
44
import type { PyProxy, PyBuffer } from "pyodide/ffi";
55
import { PromiseDelegate } from "@stlite/common";
66
import {
@@ -39,7 +39,7 @@ if (typeof global !== "undefined" && typeof global.self === "undefined") {
3939
}
4040

4141
function dispatchModuleAutoLoading(
42-
pyodide: Pyodide.PyodideInterface,
42+
pyodide: PyodideInterface,
4343
postMessage: PostMessageFn,
4444
sources: string[],
4545
): void {
@@ -54,7 +54,7 @@ script_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__
5454
`);
5555
}
5656

57-
let initPyodidePromise: Promise<Pyodide.PyodideInterface> | null = null;
57+
let initPyodidePromise: Promise<PyodideInterface> | null = null;
5858

5959
export function startWorkerEnv(
6060
defaultPyodideUrl: string,
@@ -71,7 +71,7 @@ export function startWorkerEnv(
7171
});
7272
}
7373

74-
let pyodide: Pyodide.PyodideInterface;
74+
let pyodide: PyodideInterface & { FS: any }; // XXX: This is a temporary workaround to fix the type error.
7575

7676
let httpServer: PyProxy;
7777

@@ -200,7 +200,7 @@ export function startWorkerEnv(
200200
postProgressMessage("Unpacking archives.");
201201
await Promise.all(
202202
archives.map(async (archive) => {
203-
let buffer: Parameters<Pyodide.PyodideInterface["unpackArchive"]>[0];
203+
let buffer: Parameters<PyodideInterface["unpackArchive"]>[0];
204204
if ("url" in archive) {
205205
console.debug(`Fetch an archive from ${archive.url}`);
206206
buffer = await fetch(archive.url).then((res) => res.arrayBuffer());

packages/kernel/src/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { startWorkerEnv } from "./worker-runtime";
44
import { generateRandomAppId } from "./app-id";
55

6-
const pyodideUrl = "https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.mjs";
6+
const pyodideUrl = "https://cdn.jsdelivr.net/pyodide/v0.27.2/full/pyodide.mjs";
77

88
if ("postMessage" in self) {
99
// Dedicated worker

packages/sharing/src/App.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import STREAMLIT_WHEEL from "streamlit.whl";
1818

1919
declare const EDITOR_APP_ORIGIN_REGEX: string;
2020
declare const EDITOR_APP_ORIGIN: string;
21+
const wheelUrls = {
22+
// The resolved URLs such as STLITE_LIB_WHEEL only contain the pathnames e.g. "/assets/stlite_lib-0.1.0-py3-none-any.whl"
23+
// and micropip treats such path-only URLs as local file URLs e.g. "file:////assets/stlite_lib-0.1.0-py3-none-any.whl"
24+
// since 0.7.0 due to the change by https://github.com/pyodide/micropip/pull/145,
25+
// though these URLs are actually for remote resources.
26+
// So we need to convert these path-only URLs to full URLs including the protocol explicitly.
27+
stliteLib: new URL(STLITE_LIB_WHEEL, import.meta.url).href,
28+
streamlit: new URL(STREAMLIT_WHEEL, import.meta.url).href,
29+
};
2130

2231
const editorAppOriginRegex = EDITOR_APP_ORIGIN_REGEX
2332
? new RegExp(EDITOR_APP_ORIGIN_REGEX)
@@ -94,10 +103,7 @@ st.write("Hello World")`,
94103
...makeToastKernelCallbacks(),
95104
moduleAutoLoad: true,
96105
sharedWorker: isSharedWorkerMode(),
97-
wheelUrls: {
98-
stliteLib: STLITE_LIB_WHEEL,
99-
streamlit: STREAMLIT_WHEEL,
100-
},
106+
wheelUrls,
101107
workerType: "module", // Vite loads the worker scripts as ES modules without bundling at dev time, so we need to specify the type as "module" for the "import" statements in the worker script to work.
102108
});
103109
_kernel = kernel;

requirements.dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pyodide-build==0.26.2
1+
pyodide-build==0.27.2

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -14992,10 +14992,10 @@ pure-color@^1.2.0:
1499214992
resolved "https://registry.npmjs.org/pure-color/-/pure-color-1.3.0.tgz"
1499314993
integrity sha512-QFADYnsVoBMw1srW7OVKEYjG+MbIa49s54w1MA1EDY6r2r/sTcKKYqRX1f4GYvnXP7eN/Pe9HFcX+hwzmrXRHA==
1499414994

14995-
pyodide@0.26.2:
14996-
version "0.26.2"
14997-
resolved "https://registry.npmjs.org/pyodide/-/pyodide-0.26.2.tgz"
14998-
integrity sha512-8VCRdFX83gBsWs6XP2rhG8HMaB+JaVyyav4q/EMzoV8fXH8HN6T5IISC92SNma6i1DRA3SVXA61S1rJcB8efgA==
14995+
pyodide@0.27.2:
14996+
version "0.27.2"
14997+
resolved "https://registry.yarnpkg.com/pyodide/-/pyodide-0.27.2.tgz#8cd43abe245bffbbf82031c95fd79e4bc719d83d"
14998+
integrity sha512-sfA2kiUuQVRpWI4BYnU3sX5PaTTt/xrcVEmRzRcId8DzZXGGtPgCBC0gCqjUTUYSa8ofPaSjXmzESc86yvvCHg==
1499914999
dependencies:
1500015000
ws "^8.5.0"
1500115001

0 commit comments

Comments
 (0)