Skip to content

Commit 852ade0

Browse files
committed
bump pyodide used in tests to 0.29
1 parent a3e6e19 commit 852ade0

6 files changed

Lines changed: 110 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,14 @@ jobs:
422422
shell: msys2 {0}
423423
run: PATH="$PATH:/c/Users/runneradmin/.cargo/bin" nox -s test-examples
424424

425-
test-emscripten:
426-
name: Test Emscripten
427-
runs-on: ubuntu-latest
428425
steps:
429426
- uses: actions/checkout@v6
427+
- uses: astral-sh/setup-uv@v7
430428
- uses: actions/setup-node@v6
431429
with:
432-
node-version: 18
430+
node-version: 22
433431
- run: |
434-
PYODIDE_VERSION=0.21.0
435-
436-
cd emscripten
437-
npm i pyodide@0.21.0
438-
cd node_modules/pyodide/
439-
npx -y prettier -w pyodide.asm.js
440-
EMSCRIPTEN_VERSION=$(node -p "require('./repodata.json').info.platform.split('_').slice(1).join('.')")
441-
PYTHON_VERSION=3.10
442-
443-
echo "PYODIDE_VERSION=$PYODIDE_VERSION" >> $GITHUB_ENV
444-
echo "EMSCRIPTEN_VERSION=$EMSCRIPTEN_VERSION" >> $GITHUB_ENV
445-
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
432+
uvx nox -s install-pyodide-emscripten
446433
echo "ORIG_PATH=$PATH" >> $GITHUB_ENV
447434
- uses: dtolnay/rust-toolchain@nightly
448435
with:
@@ -452,11 +439,6 @@ jobs:
452439
with:
453440
version: ${{env.EMSCRIPTEN_VERSION}}
454441
actions-cache-folder: emsdk-cache
455-
- uses: actions/setup-python@v6
456-
id: setup-python
457-
with:
458-
python-version: ${{env.PYTHON_VERSION}}
459-
- run: pip install nox
460442
- uses: actions/cache@v5
461443
with:
462444
path: |
@@ -466,4 +448,6 @@ jobs:
466448
- name: Test
467449
run: |
468450
export PATH=$ORIG_PATH:$PATH
469-
nox -s test-examples-emscripten
451+
uvx nox -s test-examples-emscripten
452+
with:
453+
UV_PYTHON: ${{ env.PYTHON_VERSION }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { loadPyodide } from "pyodide";
2+
3+
const pyodide = await loadPyodide();
4+
5+
pyodide.runPython(`
6+
import platform
7+
print(platform.platform().split("-")[1])
8+
`);

emscripten/get_python_version.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { loadPyodide } from "pyodide";
2+
3+
const pyodide = await loadPyodide();
4+
5+
pyodide.runPython(`
6+
import sys
7+
major, minor = sys.version_info[:2]
8+
print(f"{major}.{minor}")
9+
`);

emscripten/package-lock.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

emscripten/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "module",
3+
"dependencies": {
4+
"pyodide": "^0.29.1"
5+
}
6+
}

noxfile.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
2+
from contextlib import ExitStack
23
from inspect import cleandoc as heredoc
34
from glob import glob
45
from pathlib import Path
56
import shutil
67
import sys
8+
import json
79

810
import nox
911
import nox.command
@@ -227,10 +229,34 @@ def test(session: nox.Session):
227229
session.run("pytest", "setuptools_rust", "tests", *session.posargs)
228230

229231

232+
PYODIDE_VERSION = "0.29.1"
233+
EMSCRIPTEN_DIR = Path("./emscripten").resolve()
234+
235+
236+
@nox.session(name="install-pyodide-emscripten")
237+
def install_pyodide_emscripten(session: nox.Session):
238+
with session.chdir(EMSCRIPTEN_DIR):
239+
session.run("npm", "install", f"pyodide@{PYODIDE_VERSION}", external=True)
240+
emscripten_version = session.run("node", "get_emscripten_version.js", external=True, silent=True).strip()
241+
python_version = session.run("node", "get_python_version.js", external=True, silent=True).strip()
242+
243+
with ExitStack() as stack:
244+
if "GITHUB_ENV" in os.environ:
245+
out = stack.enter_context(open(os.environ["GITHUB_ENV"], "a"))
246+
else:
247+
out = sys.stdout
248+
249+
print(f"PYODIDE_VERSION={PYODIDE_VERSION}", file=out)
250+
print(f"EMSCRIPTEN_VERSION={emscripten_version}", file=out)
251+
print(f"PYTHON_VERSION={python_version}", file=out)
252+
253+
if "GITHUB_ENV" not in os.environ:
254+
print("You will need to install emscripten yourself to match the target version.")
255+
256+
230257
@nox.session(name="test-examples-emscripten")
231258
def test_examples_emscripten(session: nox.Session):
232259
session.install(".", "build")
233-
emscripten_dir = Path("./emscripten").resolve()
234260

235261
session.run(
236262
"rustup",
@@ -250,20 +276,20 @@ def test_examples_emscripten(session: nox.Session):
250276
env = os.environ.copy()
251277
env.update(
252278
RUSTUP_TOOLCHAIN="nightly",
253-
PYTHONPATH=str(emscripten_dir),
279+
PYTHONPATH=str(EMSCRIPTEN_DIR),
254280
_PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__emscripten_wasm32-emscripten",
255281
_PYTHON_HOST_PLATFORM="emscripten_3_1_14_wasm32",
256282
CARGO_BUILD_TARGET="wasm32-unknown-emscripten",
257283
CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_LINKER=str(
258-
emscripten_dir / "emcc_wrapper.py"
284+
EMSCRIPTEN_DIR / "emcc_wrapper.py"
259285
),
260-
PYO3_CONFIG_FILE=str(emscripten_dir / "pyo3_config.ini"),
286+
PYO3_CONFIG_FILE=str(EMSCRIPTEN_DIR / "pyo3_config.ini"),
261287
)
262288
with session.chdir(example):
263289
cmd = ["python", "-m", "build", "--wheel", "--no-isolation"]
264290
session.run(*cmd, env=env, external=True)
265291

266-
with session.chdir(emscripten_dir):
292+
with session.chdir(EMSCRIPTEN_DIR):
267293
session.run("node", "runner.js", str(example), external=True)
268294

269295

0 commit comments

Comments
 (0)