2021-10-12 02:05:47 +01:00
|
|
|
import platform as platform_module
|
|
|
|
|
import subprocess
|
2021-10-17 21:24:03 +01:00
|
|
|
import sys
|
2023-04-18 12:38:21 -04:00
|
|
|
import typing
|
2021-10-12 02:05:47 +01:00
|
|
|
from contextlib import contextmanager
|
2022-05-24 17:35:46 -06:00
|
|
|
from pathlib import PurePosixPath
|
2021-10-12 02:05:47 +01:00
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2025-03-24 16:58:47 +00:00
|
|
|
from cibuildwheel import platforms
|
2021-10-12 02:05:47 +01:00
|
|
|
from cibuildwheel.__main__ import main
|
2024-09-12 21:32:43 +02:00
|
|
|
from cibuildwheel.oci_container import OCIPlatform
|
2025-01-27 20:35:56 +01:00
|
|
|
from cibuildwheel.util import file
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2025-07-23 20:59:02 -04:00
|
|
|
DEFAULT_IDS = {"cp38", "cp39", "cp310", "cp311", "cp312", "cp313", "cp314", "cp314t"}
|
2025-09-22 22:23:29 +02:00
|
|
|
ALL_IDS = DEFAULT_IDS | {"cp313t", "pp38", "pp39", "pp310", "pp311", "gp311_242", "gp312_250"}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
|
2024-08-21 00:34:31 -04:00
|
|
|
@pytest.fixture
|
2022-06-27 18:30:49 +01:00
|
|
|
def mock_build_container(monkeypatch):
|
2021-10-12 02:05:47 +01:00
|
|
|
def fail_on_call(*args, **kwargs):
|
2022-09-05 13:11:46 -04:00
|
|
|
msg = "This should never be called"
|
|
|
|
|
raise RuntimeError(msg)
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
def ignore_call(*args, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
|
def nullcontext(enter_result=None):
|
|
|
|
|
yield enter_result
|
|
|
|
|
|
|
|
|
|
def ignore_context_call(*args, **kwargs):
|
|
|
|
|
return nullcontext(kwargs)
|
|
|
|
|
|
|
|
|
|
monkeypatch.setenv("CIBW_PLATFORM", "linux")
|
|
|
|
|
monkeypatch.setattr(platform_module, "machine", lambda: "x86_64")
|
|
|
|
|
|
|
|
|
|
monkeypatch.setattr(subprocess, "Popen", fail_on_call)
|
|
|
|
|
monkeypatch.setattr(subprocess, "run", ignore_call)
|
2025-01-27 20:35:56 +01:00
|
|
|
monkeypatch.setattr(file, "download", fail_on_call)
|
2025-03-24 16:58:47 +00:00
|
|
|
monkeypatch.setattr("cibuildwheel.platforms.linux.OCIContainer", ignore_context_call)
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
monkeypatch.setattr(
|
2025-03-24 16:58:47 +00:00
|
|
|
"cibuildwheel.platforms.linux.build_in_container",
|
|
|
|
|
mock.Mock(spec=platforms.linux.build_in_container),
|
2022-06-27 18:30:49 +01:00
|
|
|
)
|
2025-07-15 20:45:53 -07:00
|
|
|
monkeypatch.setattr("cibuildwheel.logger.Logger.print_summary", ignore_context_call)
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("mock_build_container", "fake_package_dir")
|
|
|
|
|
def test_build_default_launches(monkeypatch):
|
|
|
|
|
monkeypatch.setattr(sys, "argv", [*sys.argv, "--platform=linux"])
|
2025-06-10 17:57:41 -04:00
|
|
|
monkeypatch.setenv("CIBW_ARCHS", "auto64 auto32")
|
2025-05-08 12:27:05 +01:00
|
|
|
monkeypatch.delenv("CIBW_ENABLE", raising=False)
|
2021-10-17 21:24:03 +01:00
|
|
|
|
|
|
|
|
main()
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2025-11-07 18:48:20 -05:00
|
|
|
build_in_container = typing.cast("mock.Mock", platforms.linux.build_in_container)
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
assert build_in_container.call_count == 4
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
# In Python 3.8+, this can be simplified to [0].kwargs
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[0][1]
|
2025-03-24 18:00:44 +01:00
|
|
|
assert "quay.io/pypa/manylinux_2_28_x86_64" in kwargs["container"]["image"]
|
2022-06-27 18:30:49 +01:00
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.AMD64
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-01-21 18:53:01 +01:00
|
|
|
assert identifiers == {f"{x}-manylinux_x86_64" for x in DEFAULT_IDS}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[1][1]
|
2025-07-08 10:32:51 +02:00
|
|
|
assert "quay.io/pypa/manylinux_2_28_i686" in kwargs["container"]["image"]
|
2022-06-27 18:30:49 +01:00
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.i386
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-01-21 18:53:01 +01:00
|
|
|
assert identifiers == {f"{x}-manylinux_i686" for x in DEFAULT_IDS}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[2][1]
|
2024-05-11 22:24:48 +02:00
|
|
|
assert "quay.io/pypa/musllinux_1_2_x86_64" in kwargs["container"]["image"]
|
2022-06-27 18:30:49 +01:00
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.AMD64
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-01-21 18:53:01 +01:00
|
|
|
assert identifiers == {f"{x}-musllinux_x86_64" for x in DEFAULT_IDS}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[3][1]
|
2024-05-11 22:24:48 +02:00
|
|
|
assert "quay.io/pypa/musllinux_1_2_i686" in kwargs["container"]["image"]
|
2022-06-27 18:30:49 +01:00
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.i386
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-01-21 18:53:01 +01:00
|
|
|
assert identifiers == {f"{x}-musllinux_i686" for x in DEFAULT_IDS}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("mock_build_container")
|
|
|
|
|
def test_build_with_override_launches(monkeypatch, tmp_path):
|
2021-10-12 02:05:47 +01:00
|
|
|
pkg_dir = tmp_path / "cibw_package"
|
|
|
|
|
pkg_dir.mkdir()
|
|
|
|
|
|
|
|
|
|
cibw_toml = pkg_dir / "pyproject.toml"
|
|
|
|
|
cibw_toml.write_text(
|
|
|
|
|
"""
|
|
|
|
|
[tool.cibuildwheel]
|
2023-08-07 18:01:10 +02:00
|
|
|
manylinux-x86_64-image = "manylinux_2_28"
|
|
|
|
|
musllinux-x86_64-image = "musllinux_1_2"
|
2025-05-15 09:06:48 -04:00
|
|
|
enable = ["pypy", "pypy-eol", "graalpy", "cpython-freethreading"]
|
2025-06-10 17:57:41 -04:00
|
|
|
archs = ["auto64", "auto32"]
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2025-03-22 17:26:38 +01:00
|
|
|
# Before Python 3.10, use manylinux2014
|
2021-10-12 02:05:47 +01:00
|
|
|
[[tool.cibuildwheel.overrides]]
|
|
|
|
|
select = "cp3?-*"
|
2021-11-19 17:39:24 +00:00
|
|
|
manylinux-x86_64-image = "manylinux2014"
|
|
|
|
|
manylinux-i686-image = "manylinux2014"
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
[[tool.cibuildwheel.overrides]]
|
2025-02-25 20:23:01 +01:00
|
|
|
select = "cp38-manylinux_x86_64"
|
2021-10-12 02:05:47 +01:00
|
|
|
before-all = "true"
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
monkeypatch.chdir(pkg_dir)
|
2021-10-17 21:24:03 +01:00
|
|
|
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--platform=linux"])
|
2025-05-12 18:54:02 +02:00
|
|
|
monkeypatch.delenv("CIBW_ENABLE", raising=False)
|
2021-10-17 21:24:03 +01:00
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
2025-11-07 18:48:20 -05:00
|
|
|
build_in_container = typing.cast("mock.Mock", platforms.linux.build_in_container)
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2025-07-08 10:32:51 +02:00
|
|
|
assert build_in_container.call_count == 7
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[0][1]
|
|
|
|
|
assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["container"]["image"]
|
|
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.AMD64
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-02-25 20:23:01 +01:00
|
|
|
assert identifiers == {"cp38-manylinux_x86_64"}
|
|
|
|
|
assert kwargs["options"].build_options("cp38-manylinux_x86_64").before_all == "true"
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[1][1]
|
|
|
|
|
assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["container"]["image"]
|
|
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.AMD64
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2021-11-11 08:40:15 -05:00
|
|
|
assert identifiers == {
|
2022-08-11 09:21:34 +02:00
|
|
|
f"{x}-manylinux_x86_64"
|
2024-08-03 20:46:45 +02:00
|
|
|
for x in ALL_IDS
|
2025-02-12 16:51:33 +01:00
|
|
|
- {
|
2025-02-25 20:23:01 +01:00
|
|
|
"cp38",
|
2025-02-12 16:51:33 +01:00
|
|
|
"cp310",
|
|
|
|
|
"cp311",
|
|
|
|
|
"cp312",
|
|
|
|
|
"cp313",
|
|
|
|
|
"cp313t",
|
2025-07-23 20:59:02 -04:00
|
|
|
"cp314",
|
|
|
|
|
"cp314t",
|
2025-02-12 16:51:33 +01:00
|
|
|
"pp38",
|
|
|
|
|
"pp39",
|
|
|
|
|
"pp310",
|
|
|
|
|
"pp311",
|
2025-05-26 21:49:59 +02:00
|
|
|
"gp311_242",
|
2025-09-22 22:23:29 +02:00
|
|
|
"gp312_250",
|
2025-02-12 16:51:33 +01:00
|
|
|
}
|
2021-11-11 08:40:15 -05:00
|
|
|
}
|
2025-02-25 20:23:01 +01:00
|
|
|
assert kwargs["options"].build_options("cp39-manylinux_x86_64").before_all == ""
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[2][1]
|
2023-08-07 18:01:10 +02:00
|
|
|
assert "quay.io/pypa/manylinux_2_28_x86_64" in kwargs["container"]["image"]
|
2022-06-27 18:30:49 +01:00
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.AMD64
|
2021-10-12 02:05:47 +01:00
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2021-11-11 08:40:15 -05:00
|
|
|
assert identifiers == {
|
2023-08-07 12:31:37 -04:00
|
|
|
f"{x}-manylinux_x86_64"
|
2025-02-12 16:51:33 +01:00
|
|
|
for x in [
|
|
|
|
|
"cp310",
|
|
|
|
|
"cp311",
|
|
|
|
|
"cp312",
|
|
|
|
|
"cp313",
|
|
|
|
|
"cp313t",
|
2025-07-23 20:59:02 -04:00
|
|
|
"cp314",
|
|
|
|
|
"cp314t",
|
2025-02-12 16:51:33 +01:00
|
|
|
"pp38",
|
|
|
|
|
"pp39",
|
|
|
|
|
"pp310",
|
|
|
|
|
"pp311",
|
2025-05-26 21:49:59 +02:00
|
|
|
"gp311_242",
|
2025-09-22 22:23:29 +02:00
|
|
|
"gp312_250",
|
2025-02-12 16:51:33 +01:00
|
|
|
]
|
2021-11-11 08:40:15 -05:00
|
|
|
}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[3][1]
|
|
|
|
|
assert "quay.io/pypa/manylinux2014_i686" in kwargs["container"]["image"]
|
|
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.i386
|
2021-10-12 02:05:47 +01:00
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-07-08 10:32:51 +02:00
|
|
|
assert identifiers == {"cp38-manylinux_i686", "cp39-manylinux_i686"}
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 18:30:49 +01:00
|
|
|
kwargs = build_in_container.call_args_list[4][1]
|
2025-07-08 10:32:51 +02:00
|
|
|
assert "quay.io/pypa/manylinux_2_28_i686" in kwargs["container"]["image"]
|
|
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
|
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.i386
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
|
|
|
|
assert identifiers == {
|
|
|
|
|
f"{x}-manylinux_i686" for x in ALL_IDS - {"cp38", "cp39"} if "gp" not in x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kwargs = build_in_container.call_args_list[5][1]
|
2023-08-07 18:01:10 +02:00
|
|
|
assert "quay.io/pypa/musllinux_1_2_x86_64" in kwargs["container"]["image"]
|
|
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.AMD64
|
2023-08-07 18:01:10 +02:00
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-04-29 00:25:17 +02:00
|
|
|
assert identifiers == {
|
|
|
|
|
f"{x}-musllinux_x86_64" for x in ALL_IDS if "pp" not in x and "gp" not in x
|
|
|
|
|
}
|
2023-08-07 18:01:10 +02:00
|
|
|
|
2025-07-08 10:32:51 +02:00
|
|
|
kwargs = build_in_container.call_args_list[6][1]
|
2024-05-11 22:24:48 +02:00
|
|
|
assert "quay.io/pypa/musllinux_1_2_i686" in kwargs["container"]["image"]
|
2022-06-27 18:30:49 +01:00
|
|
|
assert kwargs["container"]["cwd"] == PurePosixPath("/project")
|
2024-09-12 21:32:43 +02:00
|
|
|
assert kwargs["container"]["oci_platform"] == OCIPlatform.i386
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
2025-04-29 00:25:17 +02:00
|
|
|
assert identifiers == {
|
|
|
|
|
f"{x}-musllinux_i686" for x in ALL_IDS if "pp" not in x and "gp" not in x
|
|
|
|
|
}
|