Skip to content

Commit

Permalink
Merge branch 'main' into register-js-module-is-extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane committed Feb 25, 2025
2 parents 3793e66 + 569ea4f commit da41b1a
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 206 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ CXX=em++
all: \
all-but-packages \
dist/pyodide-lock.json \
dist/console.html \
dist/pyodide.d.ts \
dist/snapshot.bin \

Expand All @@ -25,8 +24,10 @@ all-but-packages: \
\
dist/package.json \
dist/python \
dist/python_cli_entry.js \
dist/python_stdlib.zip \
dist/test.html \
dist/console.html \
dist/module_test.html \


Expand Down Expand Up @@ -252,6 +253,9 @@ dist/module_test.html: src/templates/module_test.html
dist/python: src/templates/python
cp $< $@

dist/python_cli_entry.js: src/templates/python_cli_entry.js
cp $< $@

.PHONY: dist/console.html
dist/console.html: src/templates/console.html
cp $< $@
Expand Down Expand Up @@ -312,7 +316,7 @@ $(CPYTHONLIB): emsdk/emsdk/.complete
@date +"[%F %T] done building cpython..."


dist/pyodide-lock.json: FORCE
dist/pyodide-lock.json:
make pyodide_build
@date +"[%F %T] Building packages..."
make -C packages
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Pyodide is a Python distribution for the browser and Node.js based on WebAssembl
Pyodide is a port of CPython to WebAssembly/[Emscripten](https://emscripten.org/).

Pyodide makes it possible to install and run Python packages in the browser with
[micropip](https://micropip.pyodide.org/). Any pure
Python package with a wheel available on PyPi is supported. Many packages with C
extensions have also been ported for use with Pyodide. These include many
general-purpose packages such as regex, PyYAML, lxml and scientific Python
packages including NumPy, pandas, SciPy, Matplotlib, and scikit-learn.
[micropip](https://micropip.pyodide.org/). Any pure Python package with a wheel
available on PyPi is supported. Many packages with C, C++, and Rust extensions
have also been ported for use with Pyodide. These include many general-purpose
packages such as regex, PyYAML, and cryptography, and scientific Python packages
including NumPy, pandas, SciPy, Matplotlib, and scikit-learn.

Pyodide comes with a robust Javascript ⟺ Python foreign function interface so
that you can freely mix these two languages in your code with minimal friction.
Expand Down
4 changes: 2 additions & 2 deletions cpython/patches/0001-Public-pymain_run_python.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From c37e3894a271ee8b406ffc41a0ce6f5c248914ee Mon Sep 17 00:00:00 2001
From f8a9e2d38252a032bdb617db396a047154f1bb6e Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Sun, 17 Jul 2022 14:40:39 +0100
Subject: [PATCH 1/9] Public pymain_run_python
Expand All @@ -23,5 +23,5 @@ index b602272b78b..d06d3c926b9 100644
{
PyObject *main_importer_path = NULL;
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 83ce578076b86b0231739b81ed9231bf8d9ca800 Mon Sep 17 00:00:00 2001
From 74f68027172f2b646b8ab9a8d73380b12f864cb7 Mon Sep 17 00:00:00 2001
From: ryanking13 <[email protected]>
Date: Fri, 2 Dec 2022 11:36:44 +0000
Subject: [PATCH 2/9] Add emscripten platform support to
Expand Down Expand Up @@ -44,5 +44,5 @@ index c550883e7c7..c25c8f63e77 100644
# AIX has two styles of storing shared libraries
# GNU auto_tools refer to these as svr4 and aix
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From da79a0ddc090407c1ea1d8e25da67931d1863642 Mon Sep 17 00:00:00 2001
From 32155f0ed7043dde694b7910db46f4c97f2e41d9 Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Mon, 19 Dec 2022 09:09:14 -0800
Subject: [PATCH 3/9] Allow multiprocessing.connection top level import
Expand Down Expand Up @@ -26,5 +26,5 @@ index d0582e3cd54..b96b2454d3d 100644
from . import util

--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From b86ebf295ad48ade5810032e83f98edb0e642abf Mon Sep 17 00:00:00 2001
From a761e476e8abab81106ed4f8b4422732404b65d2 Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Wed, 28 Jun 2023 10:46:19 -0700
Subject: [PATCH 4/9] Make Emscripten trampolines work with JSPI
Expand Down Expand Up @@ -382,5 +382,5 @@ index d0d54050286..85c6d2f71ae 100644
)
AC_SUBST([PLATFORM_HEADERS])
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 2d2732b55d57008545e818fc1b5ef4dca5625b9e Mon Sep 17 00:00:00 2001
From 13370805f9652e70bc19447381443afde82c9b93 Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Tue, 22 Oct 2024 15:16:03 +0200
Subject: [PATCH 5/9] Use wasm-gc based call adaptor if available
Expand Down Expand Up @@ -408,5 +408,5 @@ index a7981bc4877..ab03729266c 100644

PyStatus
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From d9e6867695c02c07420d8a15d4ae1b96ea41f553 Mon Sep 17 00:00:00 2001
From 6f2d305e8eba14fd3c49f54790f13c19fa41860b Mon Sep 17 00:00:00 2001
From: ryanking13 <[email protected]>
Date: Fri, 12 Jan 2024 00:52:57 +0900
Subject: [PATCH 6/9] Fix LONG_BIT constant to be always 32bit
Expand Down Expand Up @@ -29,5 +29,5 @@ index e2bac3bf504..ae1c1a40260 100644
#define LONG_BIT (8 * SIZEOF_LONG)
#endif
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From a35c57ed8c7f2657a7a82d900184ebe649dedfdf Mon Sep 17 00:00:00 2001
From 566d1c20df2370c4a47f21561086fb7e5f51299c Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Thu, 25 Jul 2024 14:28:57 +0200
Subject: [PATCH 7/9] Warn if ZoneInfo is imported without tzdata
Expand All @@ -25,5 +25,5 @@ index 98cdfe37ca6..35d19eae9f0 100644
# to "we cannot find this key":
#
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From ff4534318481437542f2e49348033a00354a069d Mon Sep 17 00:00:00 2001
From f09bfe83d146697b936799d97d8fe0110c61b86d Mon Sep 17 00:00:00 2001
From: Hood Chatham <[email protected]>
Date: Thu, 25 Jul 2024 14:41:37 +0200
Subject: [PATCH 8/9] Add call to `JsProxy_GetMethod` to help remove temporary
Expand Down Expand Up @@ -56,5 +56,5 @@ index 6b2e0aeaab9..9240b33b08a 100644
*method = PyObject_GetAttr(obj, name);
return 0;
--
2.34.1
2.48.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
From c627686651a46118b2a653fa61673dfc158442d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Langa?= <[email protected]>
Date: Fri, 21 Feb 2025 19:24:41 +0100
Subject: [PATCH 9/9] Skip wasm-gc on iOS Safari where it's broken

As of iOS 18.3.1, enabling wasm-gc is making the interpreter fail to load.
Downstream pyodide issue: pyodide/pyodide#5428.

macOS Safari 18.3 does not surface the issue.

Confirmed on device that disabling this restores interpreter function.
---
Python/emscripten_trampoline.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/Python/emscripten_trampoline.c b/Python/emscripten_trampoline.c
index e78a94e5e99..ff57f9e91d8 100644
--- a/Python/emscripten_trampoline.c
+++ b/Python/emscripten_trampoline.c
@@ -79,7 +79,13 @@ EM_JS(CountArgsFunc, _PyEM_GetCountArgsPtr, (), {
// i32.const -1
// )
// )
-addOnPreRun(() => {
+
+function getPyEMCountArgsPtr() {
+ let isIOS = globalThis.navigator && /iPad|iPhone|iPod/.test(navigator.platform);
+ if (isIOS) {
+ return 0;
+ }
+
// Try to initialize countArgsFunc
const code = new Uint8Array([
0x00, 0x61, 0x73, 0x6d, // \0asm magic number
@@ -151,15 +157,19 @@ addOnPreRun(() => {
0x41, 0x7f, // i32.const -1
0x0b // end function
]);
- let ptr = 0;
try {
const mod = new WebAssembly.Module(code);
const inst = new WebAssembly.Instance(mod, { e: { t: wasmTable } });
- ptr = addFunction(inst.exports.f);
+ return addFunction(inst.exports.f);
} catch (e) {
// If something goes wrong, we'll null out _PyEM_CountFuncParams and fall
// back to the JS trampoline.
+ return 0;
}
+}
+
+addOnPreRun(() => {
+ const ptr = getPyEMCountArgsPtr();
Module._PyEM_CountArgsPtr = ptr;
const offset = HEAP32[__PyEM_EMSCRIPTEN_COUNT_ARGS_OFFSET / 4];
HEAP32[(__PyRuntime + offset) / 4] = ptr;
--
2.48.1

20 changes: 11 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ What is Pyodide?
Pyodide is a port of CPython to WebAssembly/`Emscripten <https://emscripten.org/>`_.

Pyodide makes it possible to install and run Python packages in the browser with
`micropip <https://pyodide.org/en/stable/usage/api/micropip-api.html>`_. Any pure
Python package with a wheel available on PyPI is supported. Many packages with C
extensions have also been ported for use with Pyodide. These include many
general-purpose packages such as regex, pyyaml, lxml and scientific Python
packages including numpy, pandas, scipy, matplotlib, and scikit-learn.
`micropip <https://pyodide.org/en/stable/usage/api/micropip-api.html>`_. Any
pure Python package with a wheel available on PyPi is supported. Many packages
with C, C++, and Rust extensions have also been ported for use with Pyodide.
These include many general-purpose packages such as regex, PyYAML, and
cryptography, and scientific Python packages including NumPy, pandas, SciPy,
Matplotlib, and scikit-learn.

Pyodide comes with a robust Javascript ⟺ Python foreign function interface so
that you can freely mix these two languages in your code with minimal
Expand Down Expand Up @@ -43,8 +44,9 @@ Using Pyodide
usage/quickstart.md
usage/downloading-and-deploying.md
usage/index.md
usage/loading-packages.md
usage/accessing-files.md
usage/loading-packages.md
usage/building-and-testing-packages.md
usage/wasm-constraints.md
usage/type-conversions.md
usage/keyboard-interrupts.md
Expand All @@ -63,12 +65,12 @@ development process including making packages to support third party libraries.
:maxdepth: 1
:caption: Development

development/building-from-sources.md
development/new-packages.md
development/building-and-testing-packages.md
development/contributing.md
development/building-from-sources.md
development/testing.md
development/debugging.md
development/contributing.md



Project
Expand Down
5 changes: 5 additions & 0 deletions docs/project/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ myst:
- {{ Fix }} `mountNativeFS` API now correctly propagates the error. {pr}`5434`
- {{ Fix }} `registerJsModule()` now works with non-extensible JS objects, such
as ES6 modules. {pr}`5452`
- {{ Fix }} Since 0.27.1, Pyodide has been broken in iOS because iOS ships
broken wasm-gc support. Pyodide feature detects whether the runtime supports
wasm-gc and uses it if it is present. Unfortunately, iOS passes the feature
detection but wasm-gc doesn't work as expected. {pr}`5445`

### Packages

- Added `h3` 4.2.1 {pr}`5436`
- Upgraded `narwhals` to 1.24.1 {pr}`5386`
- Upgraded `rateslib` to 1.7.0 {pr}`5400`
- Upgraded Pyxel to 2.3.6 {pr}`5427`
- Added `pcodec` 0.3.3 {pr}`5432`

- {{ Breaking }} `matplotlib-pyodide` is not a default backend for matplotlib anymore.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ markers = [
[tool._pyodide]

[tool.pyodide.build]
rust_toolchain = "nightly-2025-01-15"
rust_toolchain = "nightly-2025-02-01"

[tool.codespell]
ignore-words = 'tools/codespell_ignore_words.txt'
Expand Down
2 changes: 2 additions & 0 deletions src/js/emscripten-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface EmscriptenSettings {
readonly print?: (a: string) => void;
readonly printErr?: (a: string) => void;
readonly onExit?: (code: number) => void;
readonly thisProgram?: string;
readonly arguments: readonly string[];
readonly instantiateWasm?: (
imports: { [key: string]: any },
Expand Down Expand Up @@ -49,6 +50,7 @@ export function createSettings(config: ConfigType): EmscriptenSettings {
onExit(code) {
settings.exitCode = code;
},
thisProgram: config._sysExecutable,
arguments: config.args,
API: { config } as API,
// Emscripten calls locateFile exactly one time with argument
Expand Down
6 changes: 6 additions & 0 deletions src/js/pyodide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type ConfigType = {
stdout?: (msg: string) => void;
stderr?: (msg: string) => void;
jsglobals?: object;
_sysExecutable?: string;
args: string[];
_node_mounts: string[];
env: { [key: string]: string };
Expand Down Expand Up @@ -139,6 +140,11 @@ export async function loadPyodide(
* Default: ``globalThis``
*/
jsglobals?: object;
/**
* Determine the value of ``sys.executable``.
* @ignore
*/
_sysExecutable?: string;
/**
* Command line arguments to pass to Python on startup. See `Python command
* line interface options
Expand Down
Loading

0 comments on commit da41b1a

Please sign in to comment.