Skip to content

Commit 6286d9c

Browse files
committed
feature: allow testing cp38-macosx_arm64 wheel
Per discussion in pypa#1169, the default installer used for cp38 is an Intel installer. It makes sense to skip testing arm64 wheels in this case. However, if the user choose to manually install the universal2 CPython version, then, tests shall be run on arm64. This allows users that either target 11.0+ on intel, universal2 or only build for arm64 to get the arm64 wheel tested on AppleSilicon.
1 parent 9d343ce commit 6286d9c

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

.cirrus.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ macos_arm64_task:
5656
- brew install [email protected]
5757
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
5858
<<: *RUN_TESTS
59+
60+
macos_arm64_cp38_task:
61+
macos_instance:
62+
image: ghcr.io/cirruslabs/macos-monterey-xcode
63+
64+
env:
65+
PATH: /opt/homebrew/opt/[email protected]/bin:$PATH
66+
PYTEST_ADDOPTS: --run-cp38-universal2 -k 'test_cp38_arm64_testing_universal2_installer or test_arch_auto'
67+
install_pre_requirements_script:
68+
- brew install [email protected]
69+
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
70+
- curl -fsSLO https://www.python.org/ftp/python/3.8.10/python-3.8.10-macos11.pkg
71+
- sudo installer -pkg python-3.8.10-macos11.pkg -target /
72+
- rm python-3.8.10-macos11.pkg
73+
- sh "/Applications/Python 3.8/Install Certificates.command"
74+
<<: *RUN_TESTS

cibuildwheel/macos.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ def build(options: Options, tmp_path: Path) -> None:
425425

426426
if build_options.test_command and build_options.test_selector(config.identifier):
427427
machine_arch = platform.machine()
428+
python_arch = call(
429+
"python",
430+
"-sSc",
431+
"import platform; print(platform.machine())",
432+
env=env,
433+
capture_stdout=True,
434+
).strip()
428435
testing_archs: list[Literal["x86_64", "arm64"]]
429436

430437
if config_is_arm64:
@@ -473,7 +480,8 @@ def build(options: Options, tmp_path: Path) -> None:
473480
# skip this test
474481
continue
475482

476-
if testing_arch == "arm64" and config.identifier.startswith("cp38-"):
483+
is_cp38 = config.identifier.startswith("cp38-")
484+
if testing_arch == "arm64" and is_cp38 and python_arch != "arm64":
477485
log.warning(
478486
unwrap(
479487
"""

test/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def pytest_addoption(parser) -> None:
88
"--run-emulation", action="store_true", default=False, help="run emulation tests"
99
)
1010
parser.addoption("--run-podman", action="store_true", default=False, help="run podman tests")
11+
parser.addoption(
12+
"--run-cp38-universal2",
13+
action="store_true",
14+
default=False,
15+
help="macOS cp38 uses the universal2 installer",
16+
)
1117

1218

1319
@pytest.fixture(

test/test_macos_archs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,33 @@ def test_cp38_arm64_testing(tmp_path, capfd):
167167
expected_wheels = [w for w in ALL_MACOS_WHEELS if "cp38" in w]
168168

169169
assert set(actual_wheels) == set(expected_wheels)
170+
171+
172+
def test_cp38_arm64_testing_universal2_installer(tmp_path, capfd, request):
173+
if not request.config.getoption("--run-cp38-universal2"):
174+
pytest.skip("needs --run-cp38-universal2 option to run")
175+
176+
project_dir = tmp_path / "project"
177+
basic_project.generate(project_dir)
178+
179+
actual_wheels = utils.cibuildwheel_run(
180+
project_dir,
181+
add_env={
182+
"CIBW_BUILD": "cp38-*",
183+
"CIBW_TEST_COMMAND": '''python -c "import platform; print('running tests on ' + platform.machine())"''',
184+
"CIBW_ARCHS": "x86_64,universal2,arm64",
185+
"MACOSX_DEPLOYMENT_TARGET": "11.0",
186+
},
187+
)
188+
189+
captured = capfd.readouterr()
190+
191+
assert "running tests on x86_64" in captured.out
192+
assert "running tests on arm64" in captured.out
193+
194+
warning_message = "While cibuildwheel can build CPython 3.8 universal2/arm64 wheels, we cannot test the arm64 part of them"
195+
assert warning_message not in captured.err
196+
197+
expected_wheels = [w.replace("10_9", "11_0") for w in ALL_MACOS_WHEELS if "cp38" in w]
198+
199+
assert set(actual_wheels) == set(expected_wheels)

unit_test/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
def pytest_addoption(parser):
1212
parser.addoption("--run-docker", action="store_true", default=False, help="run docker tests")
1313
parser.addoption("--run-podman", action="store_true", default=False, help="run podman tests")
14-
14+
parser.addoption(
15+
"--run-cp38-universal2",
16+
action="store_true",
17+
default=False,
18+
help="macOS cp38 uses the universal2 installer",
19+
)
20+
1521

1622
@pytest.fixture
1723
def fake_package_dir(tmp_path, monkeypatch):

0 commit comments

Comments
 (0)