Debian Codegraph @

noxfile.py

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