Skip to content

Commit e2edfb7

Browse files
committed
[SymForce] Test wheels in CI
Topic: sf-test-wheels Relative: sf-wheel-tests GitOrigin-RevId: d4dd84dac2dbc30123c3b98f8f206d67ea3cf31f
1 parent eeca6cf commit e2edfb7

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

.github/scripts/run_wheel_tests.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import asyncio
2+
import os
3+
import platform
4+
import sys
5+
import textwrap
6+
from pathlib import Path
7+
8+
9+
async def run_test(
10+
semaphore: asyncio.Semaphore, output_lock: asyncio.Lock, test_file: Path, symbolic_api: str
11+
) -> bool:
12+
async with semaphore:
13+
args = [test_file]
14+
15+
# Codegen is different on macOS; there's some nondeterminism in SymEngine, based on e.g.
16+
# unordered_map iteration order, that we need to fix. For now, this is fine, so we check
17+
# that the tests pass, but allow them to generate different code than is checked in.
18+
include_update_flag = (
19+
platform.system() == "Darwin"
20+
and test_file.name
21+
in {
22+
"symforce_codegen_test.py",
23+
"symforce_examples_robot_3d_localization_codegen_test.py",
24+
"symforce_examples_custom_factor_generation_codegen_test.py",
25+
"symforce_examples_bundle_adjustment_fixed_size_codegen_test.py",
26+
"symforce_gen_codegen_test.py",
27+
}
28+
and symbolic_api == "symengine"
29+
)
30+
if include_update_flag:
31+
args.append("--update")
32+
33+
proc = await asyncio.create_subprocess_exec(
34+
sys.executable,
35+
*args,
36+
env=dict(os.environ, SYMFORCE_WHEEL_TESTS="1", SYMFORCE_SYMBOLIC_API=symbolic_api),
37+
stderr=asyncio.subprocess.STDOUT,
38+
stdout=asyncio.subprocess.PIPE,
39+
)
40+
41+
stdout, _ = await proc.communicate()
42+
43+
if proc.returncode != 0:
44+
async with output_lock:
45+
print(
46+
textwrap.dedent(
47+
"""
48+
--------------------------------------------------------------------------------
49+
Test {test_file} on api {symbolic_api} failed with output:
50+
{output}
51+
--------------------------------------------------------------------------------
52+
"""
53+
).format(test_file=test_file, symbolic_api=symbolic_api, output=stdout.decode())
54+
)
55+
return False
56+
57+
return True
58+
59+
60+
async def main() -> int:
61+
project = Path(sys.argv[1])
62+
63+
tests = project.glob("test/*_test.py")
64+
semaphore = asyncio.Semaphore(os.cpu_count())
65+
output_lock = asyncio.Lock()
66+
tests = [(test, symbolic_api) for test in tests for symbolic_api in ("symengine", "sympy")]
67+
results = await asyncio.gather(
68+
*[run_test(semaphore, output_lock, test, symbolic_api) for test, symbolic_api in tests]
69+
)
70+
total_tests = len(results)
71+
succeeded_tests = sum(results)
72+
print(f"Ran {total_tests}, {succeeded_tests} passed, {total_tests - succeeded_tests} failed")
73+
if total_tests != succeeded_tests:
74+
for result, (test, symbolic_api) in zip(results, tests):
75+
if not result:
76+
print(f" {test} ({symbolic_api})")
77+
if total_tests != succeeded_tests:
78+
return 1
79+
return 0
80+
81+
82+
if __name__ == "__main__":
83+
sys.exit(asyncio.run(main()))

.github/workflows/build_wheels.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ jobs:
6565
# For arm64; for x86, it's at /usr/local but cmake finds that ok already
6666
GMP_ROOT: /opt/homebrew
6767
CIBW_ENVIRONMENT: SYMFORCE_REWRITE_LOCAL_DEPENDENCIES=$SYMFORCE_VERSION MACOSX_DEPLOYMENT_TARGET=${{ matrix.os.version }}.0
68+
CIBW_BEFORE_TEST: >
69+
pip install build setuptools_scm &&
70+
python -m build --wheel {project}/third_party/skymarshal --outdir /tmp/wheel-test-dist &&
71+
python -m build --wheel {project}/gen/python --outdir /tmp/wheel-test-dist &&
72+
pip install /tmp/wheel-test-dist/*
73+
CIBW_TEST_COMMAND: python {project}/.github/scripts/run_wheel_tests.py {project}
74+
CIBW_TEST_EXTRAS: dev
6875

6976
- name: Upload wheels
7077
uses: actions/upload-artifact@v4
@@ -99,6 +106,13 @@ jobs:
99106
CIBW_BEFORE_BUILD: yum install -y gmp-devel git
100107
CIBW_ENVIRONMENT: SYMFORCE_REWRITE_LOCAL_DEPENDENCIES=$SYMFORCE_VERSION
101108
CIBW_ENVIRONMENT_PASS_LINUX: SYMFORCE_VERSION
109+
CIBW_BEFORE_TEST: >
110+
pip install build setuptools_scm &&
111+
python -m build --wheel {project}/third_party/skymarshal --outdir /tmp/wheel-test-dist &&
112+
python -m build --wheel {project}/gen/python --outdir /tmp/wheel-test-dist &&
113+
pip install /tmp/wheel-test-dist/*
114+
CIBW_TEST_COMMAND: python {project}/.github/scripts/run_wheel_tests.py {project}
115+
CIBW_TEST_EXTRAS: dev
102116

103117
- name: Upload Wheels
104118
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)