-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
noxfile.py
91 lines (77 loc) · 2.93 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import json
import sys
from pathlib import Path
import nox
PYODIDE_VERSION = os.getenv("PYODIDE_VERSION", "0.23.4")
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS")
GITHUB_ENV = os.getenv("GITHUB_ENV")
MSRV = "1.74.0"
def append_to_github_env(name: str, value: str):
if not GITHUB_ACTIONS or not GITHUB_ENV:
return
with open(GITHUB_ENV, "w+") as f:
f.write(f"{name}={value}\n")
@nox.session(name="update-pyo3", python=False)
def update_pyo3(session: nox.Session):
# TODO: support updating major and minor versions by editing Cargo.toml first
test_crate_dir = Path("./test-crates").resolve()
for root, _, files in os.walk(test_crate_dir):
if "Cargo.lock" in files:
cargo_lock_path = Path(root) / "Cargo.lock"
with open(cargo_lock_path, "r") as lock_file:
content = lock_file.read()
if 'name = "pyo3"' in content:
with session.chdir(root):
session.run("cargo", f"+{MSRV}", "update", "-p", "pyo3", external=True)
elif 'name = "pyo3-ffi"' in content:
with session.chdir(root):
session.run("cargo", f"+{MSRV}", "update", "-p", "pyo3-ffi", external=True)
@nox.session(name="setup-pyodide", python=False)
def setup_pyodide(session: nox.Session):
tests_dir = Path("./tests").resolve()
with session.chdir(tests_dir):
session.run(
"npm",
"i",
"--no-save",
f"pyodide@{PYODIDE_VERSION}",
"prettier",
external=True,
)
with session.chdir(tests_dir / "node_modules" / "pyodide"):
session.run(
"node",
"../prettier/bin/prettier.cjs",
"-w",
"pyodide.asm.js",
external=True,
)
with open("repodata.json") as f:
emscripten_version = json.load(f)["info"]["platform"].split("_", 1)[1].replace("_", ".")
append_to_github_env("EMSCRIPTEN_VERSION", emscripten_version)
@nox.session(name="test-emscripten", python=False)
def test_emscripten(session: nox.Session):
tests_dir = Path("./tests").resolve()
test_crates = [
"test-crates/pyo3-pure",
"test-crates/pyo3-mixed",
]
for crate in test_crates:
crate = Path(crate).resolve()
ver = sys.version_info
session.run("cargo", "build", external=True)
session.run(
tests_dir.parent / "target" / "debug" / "maturin",
"build",
"-m",
str(crate / "Cargo.toml"),
"--target",
"wasm32-unknown-emscripten",
"-i",
f"python{ver.major}.{ver.minor}",
env={"RUSTUP_TOOLCHAIN": "nightly"},
external=True,
)
with session.chdir(tests_dir):
session.run("node", "emscripten_runner.js", str(crate), external=True)