Make container-engine a build (non-global) option (#1792)
This commit is contained in:
@@ -5,13 +5,13 @@ from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
import cibuildwheel.linux
|
||||
import cibuildwheel.oci_container
|
||||
from cibuildwheel.oci_container import OCIContainerEngineConfig
|
||||
from cibuildwheel.options import CommandLineArguments, Options
|
||||
|
||||
|
||||
def test_linux_container_split(tmp_path: Path, monkeypatch):
|
||||
"""
|
||||
Tests splitting linux builds by container image and before_all
|
||||
Tests splitting linux builds by container image, container engine, and before_all
|
||||
"""
|
||||
|
||||
args = CommandLineArguments.defaults()
|
||||
@@ -28,13 +28,17 @@ def test_linux_container_split(tmp_path: Path, monkeypatch):
|
||||
archs = "x86_64 i686"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp{38,39,310}-*"
|
||||
select = "cp{37,38,39,310}-*"
|
||||
manylinux-x86_64-image = "other_container_image"
|
||||
manylinux-i686-image = "other_container_image"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp39-*"
|
||||
before-all = "echo 'a cp39-only command'"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp310-*"
|
||||
container-engine = "docker; create_args: --privileged"
|
||||
"""
|
||||
)
|
||||
)
|
||||
@@ -55,21 +59,35 @@ def test_linux_container_split(tmp_path: Path, monkeypatch):
|
||||
def before_alls(step):
|
||||
return [options.build_options(c.identifier).before_all for c in step.platform_configs]
|
||||
|
||||
def container_engines(step):
|
||||
return [options.build_options(c.identifier).container_engine for c in step.platform_configs]
|
||||
|
||||
pprint(build_steps)
|
||||
|
||||
default_container_engine = OCIContainerEngineConfig(name="docker")
|
||||
|
||||
assert build_steps[0].container_image == "normal_container_image"
|
||||
assert identifiers(build_steps[0]) == [
|
||||
"cp36-manylinux_x86_64",
|
||||
"cp37-manylinux_x86_64",
|
||||
"cp311-manylinux_x86_64",
|
||||
"cp312-manylinux_x86_64",
|
||||
]
|
||||
assert before_alls(build_steps[0]) == ["", "", "", ""]
|
||||
assert before_alls(build_steps[0]) == [""] * 3
|
||||
assert container_engines(build_steps[0]) == [default_container_engine] * 3
|
||||
|
||||
assert build_steps[1].container_image == "other_container_image"
|
||||
assert identifiers(build_steps[1]) == ["cp38-manylinux_x86_64", "cp310-manylinux_x86_64"]
|
||||
assert before_alls(build_steps[1]) == ["", ""]
|
||||
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
|
||||
|
||||
assert build_steps[2].container_image == "other_container_image"
|
||||
assert identifiers(build_steps[2]) == ["cp39-manylinux_x86_64"]
|
||||
assert before_alls(build_steps[2]) == ["echo 'a cp39-only command'"]
|
||||
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",))
|
||||
]
|
||||
|
||||
@@ -340,7 +340,7 @@ def test_create_args_volume(tmp_path: Path, container_engine):
|
||||
test_mount_dir.mkdir()
|
||||
(test_mount_dir / "test_file.txt").write_text("1234")
|
||||
container_engine = OCIContainerEngineConfig(
|
||||
name="docker", create_args=[f"--volume={test_mount_dir}:/test_mount"]
|
||||
name="docker", create_args=(f"--volume={test_mount_dir}:/test_mount",)
|
||||
)
|
||||
|
||||
with OCIContainer(
|
||||
@@ -356,37 +356,37 @@ def test_create_args_volume(tmp_path: Path, container_engine):
|
||||
(
|
||||
"docker",
|
||||
"docker",
|
||||
[],
|
||||
(),
|
||||
),
|
||||
(
|
||||
"docker;create_args:",
|
||||
"docker",
|
||||
[],
|
||||
(),
|
||||
),
|
||||
(
|
||||
"docker;create_args:--abc --def",
|
||||
"docker",
|
||||
["--abc", "--def"],
|
||||
("--abc", "--def"),
|
||||
),
|
||||
(
|
||||
"docker; create_args: --abc --def",
|
||||
"docker",
|
||||
["--abc", "--def"],
|
||||
("--abc", "--def"),
|
||||
),
|
||||
(
|
||||
"name:docker; create_args: --abc --def",
|
||||
"docker",
|
||||
["--abc", "--def"],
|
||||
("--abc", "--def"),
|
||||
),
|
||||
(
|
||||
'docker; create_args: --some-option="value with spaces"',
|
||||
"docker",
|
||||
["--some-option=value with spaces"],
|
||||
("--some-option=value with spaces",),
|
||||
),
|
||||
(
|
||||
'docker; create_args: --some-option="value; with; semicolons" --another-option',
|
||||
"docker",
|
||||
["--some-option=value; with; semicolons", "--another-option"],
|
||||
("--some-option=value; with; semicolons", "--another-option"),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -206,49 +206,49 @@ def test_toml_environment_quoting(tmp_path: Path, toml_assignment, result_value)
|
||||
(
|
||||
'container-engine = "podman"',
|
||||
"podman",
|
||||
[],
|
||||
(),
|
||||
False,
|
||||
),
|
||||
(
|
||||
'container-engine = {name = "podman"}',
|
||||
"podman",
|
||||
[],
|
||||
(),
|
||||
False,
|
||||
),
|
||||
(
|
||||
'container-engine = "docker; create_args: --some-option"',
|
||||
"docker",
|
||||
["--some-option"],
|
||||
("--some-option",),
|
||||
False,
|
||||
),
|
||||
(
|
||||
'container-engine = {name = "docker", create-args = ["--some-option"]}',
|
||||
"docker",
|
||||
["--some-option"],
|
||||
("--some-option",),
|
||||
False,
|
||||
),
|
||||
(
|
||||
'container-engine = {name = "docker", create-args = ["--some-option", "value that contains spaces"]}',
|
||||
"docker",
|
||||
["--some-option", "value that contains spaces"],
|
||||
("--some-option", "value that contains spaces"),
|
||||
False,
|
||||
),
|
||||
(
|
||||
'container-engine = {name = "docker", create-args = ["--some-option", "value;that;contains;semicolons"]}',
|
||||
"docker",
|
||||
["--some-option", "value;that;contains;semicolons"],
|
||||
("--some-option", "value;that;contains;semicolons"),
|
||||
False,
|
||||
),
|
||||
(
|
||||
'container-engine = {name = "docker", disable-host-mount = true}',
|
||||
"docker",
|
||||
[],
|
||||
(),
|
||||
True,
|
||||
),
|
||||
(
|
||||
'container-engine = {name = "docker", disable_host_mount = true}',
|
||||
"docker",
|
||||
[],
|
||||
(),
|
||||
True,
|
||||
),
|
||||
],
|
||||
@@ -269,7 +269,7 @@ def test_container_engine_option(
|
||||
)
|
||||
|
||||
options = Options(platform="linux", command_line_arguments=args, env={})
|
||||
parsed_container_engine = options.globals.container_engine
|
||||
parsed_container_engine = options.build_options(None).container_engine
|
||||
|
||||
assert parsed_container_engine.name == result_name
|
||||
assert parsed_container_engine.create_args == result_create_args
|
||||
|
||||
@@ -20,11 +20,39 @@ def test_validate_default_schema():
|
||||
assert validator(example) is not None
|
||||
|
||||
|
||||
def test_validate_bad_container_engine():
|
||||
def test_validate_container_engine():
|
||||
"""
|
||||
This test checks container engine can be overridden - it used to be a
|
||||
global option but is now a build option.
|
||||
"""
|
||||
|
||||
example = tomllib.loads(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
container-engine = "docker"
|
||||
|
||||
[tool.cibuildwheel.linux]
|
||||
container-engine = "docker"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "*_x86_64"
|
||||
container-engine = "docker; create_args: --platform linux/arm64/v8"
|
||||
"""
|
||||
)
|
||||
|
||||
validator = validate_pyproject.api.Validator()
|
||||
assert validator(example) is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform", ["macos", "windows"])
|
||||
def test_validate_bad_container_engine(platform: str):
|
||||
"""
|
||||
container-engine is not a valid option for macos or windows
|
||||
"""
|
||||
example = tomllib.loads(
|
||||
f"""
|
||||
[tool.cibuildwheel.{platform}]
|
||||
container-engine = "docker"
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user