2026-05-28 00:20:08 +02:00
|
|
|
from __future__ import annotations
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2026-05-28 00:20:08 +02:00
|
|
|
import textwrap
|
|
|
|
|
from pprint import pprint
|
2024-10-22 10:16:59 -04:00
|
|
|
|
2026-06-07 05:10:32 +02:00
|
|
|
import pytest
|
|
|
|
|
|
2025-03-24 16:58:47 +00:00
|
|
|
import cibuildwheel.platforms.linux
|
2026-06-07 05:10:32 +02:00
|
|
|
from cibuildwheel.errors import ConfigurationError
|
2024-05-20 07:47:10 +01:00
|
|
|
from cibuildwheel.oci_container import OCIContainerEngineConfig
|
2022-11-26 15:54:08 +00:00
|
|
|
from cibuildwheel.options import CommandLineArguments, Options
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2026-05-28 00:20:08 +02:00
|
|
|
TYPE_CHECKING = False
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def test_linux_container_split(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
2021-10-12 02:05:47 +01:00
|
|
|
"""
|
2024-05-20 07:47:10 +01:00
|
|
|
Tests splitting linux builds by container image, container engine, and before_all
|
2021-10-12 02:05:47 +01:00
|
|
|
"""
|
|
|
|
|
|
2022-11-26 15:54:08 +00:00
|
|
|
args = CommandLineArguments.defaults()
|
2021-10-12 02:05:47 +01:00
|
|
|
args.platform = "linux"
|
|
|
|
|
|
|
|
|
|
(tmp_path / "pyproject.toml").write_text(
|
|
|
|
|
textwrap.dedent(
|
|
|
|
|
"""
|
|
|
|
|
[tool.cibuildwheel]
|
2022-06-27 17:46:22 +01:00
|
|
|
manylinux-x86_64-image = "normal_container_image"
|
|
|
|
|
manylinux-i686-image = "normal_container_image"
|
2021-10-12 02:05:47 +01:00
|
|
|
build = "*-manylinux_x86_64"
|
2025-04-29 00:25:17 +02:00
|
|
|
skip = "[gp]p*"
|
2021-10-12 02:05:47 +01:00
|
|
|
archs = "x86_64 i686"
|
|
|
|
|
|
|
|
|
|
[[tool.cibuildwheel.overrides]]
|
2026-05-11 03:19:36 +02:00
|
|
|
select = "cp{39,310,311}-*"
|
2022-06-27 17:46:22 +01:00
|
|
|
manylinux-x86_64-image = "other_container_image"
|
|
|
|
|
manylinux-i686-image = "other_container_image"
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
[[tool.cibuildwheel.overrides]]
|
2026-05-11 03:19:36 +02:00
|
|
|
select = "cp310-*"
|
|
|
|
|
before-all = "echo 'a cp310-only command'"
|
2024-05-20 07:47:10 +01:00
|
|
|
|
|
|
|
|
[[tool.cibuildwheel.overrides]]
|
2026-05-11 03:19:36 +02:00
|
|
|
select = "cp311-*"
|
2024-05-20 07:47:10 +01:00
|
|
|
container-engine = "docker; create_args: --privileged"
|
2021-10-12 02:05:47 +01:00
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
monkeypatch.chdir(tmp_path)
|
2022-12-05 19:18:54 +00:00
|
|
|
options = Options("linux", command_line_arguments=args, env={})
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2025-03-24 16:58:47 +00:00
|
|
|
python_configurations = cibuildwheel.platforms.linux.get_python_configurations(
|
2021-10-12 02:05:47 +01:00
|
|
|
options.globals.build_selector, options.globals.architectures
|
|
|
|
|
)
|
|
|
|
|
|
2025-03-24 16:58:47 +00:00
|
|
|
build_steps = list(cibuildwheel.platforms.linux.get_build_steps(options, python_configurations))
|
2021-10-12 02:05:47 +01:00
|
|
|
|
|
|
|
|
# helper functions to extract test info
|
2025-03-24 16:58:47 +00:00
|
|
|
def identifiers(step: cibuildwheel.platforms.linux.BuildStep) -> list[str]:
|
2021-10-12 02:05:47 +01:00
|
|
|
return [c.identifier for c in step.platform_configs]
|
|
|
|
|
|
2025-03-24 16:58:47 +00:00
|
|
|
def before_alls(step: cibuildwheel.platforms.linux.BuildStep) -> list[str]:
|
2021-10-12 02:05:47 +01:00
|
|
|
return [options.build_options(c.identifier).before_all for c in step.platform_configs]
|
|
|
|
|
|
2025-03-24 16:58:47 +00:00
|
|
|
def container_engines(
|
|
|
|
|
step: cibuildwheel.platforms.linux.BuildStep,
|
|
|
|
|
) -> list[OCIContainerEngineConfig]:
|
2024-05-20 07:47:10 +01:00
|
|
|
return [options.build_options(c.identifier).container_engine for c in step.platform_configs]
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
pprint(build_steps)
|
|
|
|
|
|
2024-05-20 07:47:10 +01:00
|
|
|
default_container_engine = OCIContainerEngineConfig(name="docker")
|
|
|
|
|
|
2025-02-25 20:23:01 +01:00
|
|
|
assert build_steps[0].container_image == "other_container_image"
|
2026-05-11 03:19:36 +02:00
|
|
|
assert identifiers(build_steps[0]) == ["cp39-manylinux_x86_64"]
|
2025-02-25 20:23:01 +01:00
|
|
|
assert before_alls(build_steps[0]) == [""]
|
|
|
|
|
assert container_engines(build_steps[0]) == [default_container_engine]
|
|
|
|
|
|
|
|
|
|
assert build_steps[1].container_image == "other_container_image"
|
2026-05-11 03:19:36 +02:00
|
|
|
assert identifiers(build_steps[1]) == ["cp310-manylinux_x86_64"]
|
|
|
|
|
assert before_alls(build_steps[1]) == ["echo 'a cp310-only command'"]
|
2025-02-25 20:23:01 +01:00
|
|
|
assert container_engines(build_steps[1]) == [default_container_engine]
|
|
|
|
|
|
|
|
|
|
assert build_steps[2].container_image == "other_container_image"
|
2026-05-11 03:19:36 +02:00
|
|
|
assert identifiers(build_steps[2]) == ["cp311-manylinux_x86_64"]
|
2025-02-25 20:23:01 +01:00
|
|
|
assert before_alls(build_steps[2]) == [""]
|
|
|
|
|
assert container_engines(build_steps[2]) == [
|
|
|
|
|
OCIContainerEngineConfig(name="docker", create_args=("--privileged",))
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
assert build_steps[3].container_image == "normal_container_image"
|
|
|
|
|
assert identifiers(build_steps[3]) == [
|
2023-08-07 12:31:37 -04:00
|
|
|
"cp312-manylinux_x86_64",
|
2024-08-03 20:46:45 +02:00
|
|
|
"cp313-manylinux_x86_64",
|
2025-07-23 20:59:02 -04:00
|
|
|
"cp314-manylinux_x86_64",
|
|
|
|
|
"cp314t-manylinux_x86_64",
|
2026-08-05 02:26:00 +02:00
|
|
|
"cp315-manylinux_x86_64",
|
|
|
|
|
"cp315t-manylinux_x86_64",
|
2022-08-11 09:21:34 +02:00
|
|
|
]
|
2026-08-05 02:26:00 +02:00
|
|
|
assert before_alls(build_steps[3]) == [""] * 6
|
|
|
|
|
assert container_engines(build_steps[3]) == [default_container_engine] * 6
|
2026-06-07 05:10:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_package_dir_outside_working_directory_raises_configuration_error(
|
|
|
|
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
|
|
|
) -> None:
|
|
|
|
|
work_dir = tmp_path / "work"
|
|
|
|
|
work_dir.mkdir()
|
|
|
|
|
package_dir = tmp_path / "package"
|
|
|
|
|
package_dir.mkdir()
|
|
|
|
|
package_dir.joinpath("pyproject.toml").touch()
|
|
|
|
|
|
|
|
|
|
monkeypatch.chdir(work_dir)
|
|
|
|
|
|
|
|
|
|
command_line_arguments = CommandLineArguments.defaults()
|
|
|
|
|
command_line_arguments.package_dir = package_dir
|
|
|
|
|
options = Options(platform="linux", command_line_arguments=command_line_arguments, env={})
|
|
|
|
|
|
|
|
|
|
with pytest.raises(
|
|
|
|
|
ConfigurationError, match="package_dir must be inside the working directory"
|
|
|
|
|
):
|
|
|
|
|
cibuildwheel.platforms.linux.build(options, tmp_path / "build")
|