2022-07-14 13:36:57 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
import textwrap
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
import pytest
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
import cibuildwheel.linux
|
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
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
skip = "pp*"
|
|
|
|
|
archs = "x86_64 i686"
|
|
|
|
|
|
|
|
|
|
[[tool.cibuildwheel.overrides]]
|
2024-05-20 07:47:10 +01:00
|
|
|
select = "cp{37,38,39,310}-*"
|
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]]
|
|
|
|
|
select = "cp39-*"
|
|
|
|
|
before-all = "echo 'a cp39-only command'"
|
2024-05-20 07:47:10 +01:00
|
|
|
|
|
|
|
|
[[tool.cibuildwheel.overrides]]
|
|
|
|
|
select = "cp310-*"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
python_configurations = cibuildwheel.linux.get_python_configurations(
|
|
|
|
|
options.globals.build_selector, options.globals.architectures
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
build_steps = list(cibuildwheel.linux.get_build_steps(options, python_configurations))
|
|
|
|
|
|
|
|
|
|
# helper functions to extract test info
|
2024-10-22 10:16:59 -04:00
|
|
|
def identifiers(step: cibuildwheel.linux.BuildStep) -> list[str]:
|
2021-10-12 02:05:47 +01:00
|
|
|
return [c.identifier for c in step.platform_configs]
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def before_alls(step: cibuildwheel.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]
|
|
|
|
|
|
2024-10-22 10:16:59 -04:00
|
|
|
def container_engines(step: cibuildwheel.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")
|
|
|
|
|
|
2022-06-27 17:46:22 +01:00
|
|
|
assert build_steps[0].container_image == "normal_container_image"
|
2022-08-11 09:21:34 +02:00
|
|
|
assert identifiers(build_steps[0]) == [
|
|
|
|
|
"cp36-manylinux_x86_64",
|
|
|
|
|
"cp311-manylinux_x86_64",
|
2023-08-07 12:31:37 -04:00
|
|
|
"cp312-manylinux_x86_64",
|
2024-08-03 20:46:45 +02:00
|
|
|
"cp313-manylinux_x86_64",
|
2022-08-11 09:21:34 +02:00
|
|
|
]
|
2024-08-03 20:46:45 +02:00
|
|
|
assert before_alls(build_steps[0]) == [""] * 4
|
|
|
|
|
assert container_engines(build_steps[0]) == [default_container_engine] * 4
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 17:46:22 +01:00
|
|
|
assert build_steps[1].container_image == "other_container_image"
|
2024-05-20 07:47:10 +01:00
|
|
|
assert identifiers(build_steps[1]) == ["cp37-manylinux_x86_64", "cp38-manylinux_x86_64"]
|
|
|
|
|
assert before_alls(build_steps[1]) == [""] * 2
|
|
|
|
|
assert container_engines(build_steps[1]) == [default_container_engine] * 2
|
2021-10-12 02:05:47 +01:00
|
|
|
|
2022-06-27 17:46:22 +01:00
|
|
|
assert build_steps[2].container_image == "other_container_image"
|
2021-10-12 02:05:47 +01:00
|
|
|
assert identifiers(build_steps[2]) == ["cp39-manylinux_x86_64"]
|
|
|
|
|
assert before_alls(build_steps[2]) == ["echo 'a cp39-only command'"]
|
2024-05-20 07:47:10 +01:00
|
|
|
assert container_engines(build_steps[2]) == [default_container_engine]
|
|
|
|
|
|
|
|
|
|
assert build_steps[3].container_image == "other_container_image"
|
|
|
|
|
assert identifiers(build_steps[3]) == ["cp310-manylinux_x86_64"]
|
|
|
|
|
assert before_alls(build_steps[3]) == [""]
|
|
|
|
|
assert container_engines(build_steps[3]) == [
|
|
|
|
|
OCIContainerEngineConfig(name="docker", create_args=("--privileged",))
|
|
|
|
|
]
|