feat: adding overrides
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
from pathlib import Path
|
||||
|
||||
from cibuildwheel.__main__ import get_build_identifiers
|
||||
from cibuildwheel.environment import parse_environment
|
||||
from cibuildwheel.options import _get_pinned_docker_images, compute_options
|
||||
from cibuildwheel.util import AllBuildOptions
|
||||
|
||||
PYPROJECT_1 = """
|
||||
[tool.cibuildwheel]
|
||||
build = ["cp38*", "cp37*"]
|
||||
environment = {FOO="BAR"}
|
||||
|
||||
test-command = "pyproject"
|
||||
|
||||
manylinux-x86_64-image = "manylinux1"
|
||||
|
||||
[tool.cibuildwheel.macos]
|
||||
test-requires = "else"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp37*"
|
||||
test-command = "pyproject-override"
|
||||
manylinux-x86_64-image = "manylinux2014"
|
||||
"""
|
||||
|
||||
|
||||
def test_all_build_options_1(tmp_path):
|
||||
with tmp_path.joinpath("pyproject.toml").open("w") as f:
|
||||
f.write(PYPROJECT_1)
|
||||
|
||||
all_build_options, build_options_by_selector = compute_options(
|
||||
"linux", tmp_path, Path("dist"), None, None, False
|
||||
)
|
||||
|
||||
identifiers = get_build_identifiers(
|
||||
"linux", all_build_options.build_selector, all_build_options.architectures
|
||||
)
|
||||
|
||||
build_options = AllBuildOptions(all_build_options, build_options_by_selector, identifiers)
|
||||
|
||||
override_display = """\
|
||||
test_command:
|
||||
*: 'pyproject'
|
||||
cp37*: 'pyproject-override'"""
|
||||
|
||||
assert override_display in str(build_options)
|
||||
|
||||
assert build_options.environment == parse_environment('FOO="BAR"')
|
||||
|
||||
all_pinned_docker_images = _get_pinned_docker_images()
|
||||
pinned_x86_64_docker_image = all_pinned_docker_images["x86_64"]
|
||||
|
||||
local = build_options["cp38-manylinux_x86_64"]
|
||||
assert local.manylinux_images is not None
|
||||
assert local.test_command == "pyproject"
|
||||
assert local.manylinux_images["x86_64"] == pinned_x86_64_docker_image["manylinux1"]
|
||||
|
||||
local = build_options["cp37-manylinux_x86_64"]
|
||||
assert local.manylinux_images is not None
|
||||
assert local.test_command == "pyproject-override"
|
||||
assert local.manylinux_images["x86_64"] == pinned_x86_64_docker_image["manylinux2014"]
|
||||
@@ -18,13 +18,13 @@ def test_output_dir(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].output_dir == OUTPUT_DIR
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == OUTPUT_DIR
|
||||
|
||||
|
||||
def test_output_dir_default(platform, intercepted_build_args, monkeypatch):
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].output_dir == Path("wheelhouse")
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == Path("wheelhouse")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("also_set_environment", [False, True])
|
||||
@@ -37,7 +37,7 @@ def test_output_dir_argument(also_set_environment, platform, intercepted_build_a
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].output_dir == OUTPUT_DIR
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == OUTPUT_DIR
|
||||
|
||||
|
||||
def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty):
|
||||
@@ -49,7 +49,7 @@ def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_emp
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
intercepted_build_selector = intercepted_build_args.args[0].general_build_options.build_selector
|
||||
assert isinstance(intercepted_build_selector, BuildSelector)
|
||||
assert intercepted_build_selector("build24-this")
|
||||
assert not intercepted_build_selector("skip65-that")
|
||||
@@ -98,9 +98,12 @@ def test_manylinux_images(
|
||||
main()
|
||||
|
||||
if platform == "linux":
|
||||
assert fnmatch(intercepted_build_args.args[0].manylinux_images[architecture], full_image)
|
||||
assert fnmatch(
|
||||
intercepted_build_args.args[0].general_build_options.manylinux_images[architecture],
|
||||
full_image,
|
||||
)
|
||||
else:
|
||||
assert intercepted_build_args.args[0].manylinux_images is None
|
||||
assert intercepted_build_args.args[0].general_build_options.manylinux_images is None
|
||||
|
||||
|
||||
def get_default_repair_command(platform):
|
||||
@@ -129,7 +132,7 @@ def test_repair_command(
|
||||
main()
|
||||
|
||||
expected_repair = repair_command or get_default_repair_command(platform)
|
||||
assert intercepted_build_args.args[0].repair_command == expected_repair
|
||||
assert intercepted_build_args.args[0].general_build_options.repair_command == expected_repair
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -147,7 +150,7 @@ def test_environment(environment, platform_specific, platform, intercepted_build
|
||||
|
||||
main()
|
||||
|
||||
intercepted_environment = intercepted_build_args.args[0].environment
|
||||
intercepted_environment = intercepted_build_args.args[0].general_build_options.environment
|
||||
assert isinstance(intercepted_environment, ParsedEnvironment)
|
||||
assert intercepted_environment.as_dictionary(prev_environment={}) == environment
|
||||
|
||||
@@ -166,7 +169,10 @@ def test_test_requires(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].test_requires == (test_requires or "").split()
|
||||
assert (
|
||||
intercepted_build_args.args[0].general_build_options.test_requires
|
||||
== (test_requires or "").split()
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_extras", [None, "extras"])
|
||||
@@ -181,7 +187,7 @@ def test_test_extras(test_extras, platform_specific, platform, intercepted_build
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].test_extras == (
|
||||
assert intercepted_build_args.args[0].general_build_options.test_extras == (
|
||||
"[" + test_extras + "]" if test_extras else ""
|
||||
)
|
||||
|
||||
@@ -200,7 +206,7 @@ def test_test_command(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].test_command == (test_command or "")
|
||||
assert intercepted_build_args.args[0].general_build_options.test_command == (test_command or "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("before_build", [None, "before --build"])
|
||||
@@ -217,7 +223,7 @@ def test_before_build(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].before_build == (before_build or "")
|
||||
assert intercepted_build_args.args[0].general_build_options.before_build == (before_build or "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("build_verbosity", [None, 0, 2, -2, 4, -4])
|
||||
@@ -235,7 +241,9 @@ def test_build_verbosity(
|
||||
main()
|
||||
|
||||
expected_verbosity = max(-3, min(3, int(build_verbosity or 0)))
|
||||
assert intercepted_build_args.args[0].build_verbosity == expected_verbosity
|
||||
assert (
|
||||
intercepted_build_args.args[0].general_build_options.build_verbosity == expected_verbosity
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -286,4 +294,4 @@ def test_before_all(before_all, platform_specific, platform, intercepted_build_a
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].before_all == (before_all or "")
|
||||
assert intercepted_build_args.args[0].general_build_options.before_all == (before_all or "")
|
||||
|
||||
@@ -246,3 +246,48 @@ def test_dig_first(ignore_empty):
|
||||
(d4, "other"),
|
||||
ignore_empty=ignore_empty,
|
||||
)
|
||||
|
||||
|
||||
PYPROJECT_2 = """
|
||||
[tool.cibuildwheel]
|
||||
build = ["cp38*", "cp37*"]
|
||||
environment = {FOO="BAR"}
|
||||
|
||||
test-command = "pyproject"
|
||||
|
||||
manylinux-x86_64-image = "manylinux1"
|
||||
|
||||
[tool.cibuildwheel.macos]
|
||||
test-requires = "else"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp37*"
|
||||
test-command = "pyproject-override"
|
||||
manylinux-x86_64-image = "manylinux2014"
|
||||
"""
|
||||
|
||||
|
||||
def test_pyproject_2(tmp_path, platform):
|
||||
with tmp_path.joinpath("pyproject.toml").open("w") as f:
|
||||
f.write(PYPROJECT_2)
|
||||
|
||||
options = ConfigOptions(tmp_path, platform=platform)
|
||||
assert options("test-command") == "pyproject"
|
||||
assert options.override("random")("test-command") == "pyproject"
|
||||
assert options.override("cp37*")("test-command") == "pyproject-override"
|
||||
|
||||
|
||||
def test_overrides_not_a_list(tmp_path, platform):
|
||||
with tmp_path.joinpath("pyproject.toml").open("w") as f:
|
||||
f.write(
|
||||
"""\
|
||||
[tool.cibuildwheel]
|
||||
build = ["cp38*", "cp37*"]
|
||||
[tool.cibuildwheel.overrides]
|
||||
select = "cp37*"
|
||||
test-command = "pyproject-override"
|
||||
"""
|
||||
)
|
||||
|
||||
with pytest.raises(ConfigOptionError):
|
||||
ConfigOptions(tmp_path, platform=platform)
|
||||
|
||||
Reference in New Issue
Block a user