refactor: Override options redesign
* Add test for defaults, fix platform detection * Improve correctness of reader.identifier with block * Fix options test to be multiplatform * 'Refactored by Sourcery' docs: write a section on overrides tests: test docker launches feat: add identifiers to launches test: add test for correct build step generation Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
MOCK_PACKAGE_DIR = Path("some_package_dir")
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--run-docker", action="store_true", default=False, help="run docker tests")
|
||||
@@ -17,3 +22,22 @@ def pytest_collection_modifyitems(config, items):
|
||||
for item in items:
|
||||
if "docker" in item.keywords:
|
||||
item.add_marker(skip_docker)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_package_dir(monkeypatch):
|
||||
"""
|
||||
Monkey-patch enough for the main() function to run
|
||||
"""
|
||||
real_path_exists = Path.exists
|
||||
|
||||
def mock_path_exists(path):
|
||||
if path == MOCK_PACKAGE_DIR / "setup.py":
|
||||
return True
|
||||
else:
|
||||
return real_path_exists(path)
|
||||
|
||||
args = ["cibuildwheel", str(MOCK_PACKAGE_DIR)]
|
||||
monkeypatch.setattr(Path, "exists", mock_path_exists)
|
||||
monkeypatch.setattr(sys, "argv", args)
|
||||
return args
|
||||
|
||||
@@ -25,19 +25,19 @@ elif pm == "s390x":
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_simple():
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
assert container.call(["echo", "hello"], capture_output=True) == "hello\n"
|
||||
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_no_lf():
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
assert container.call(["printf", "hello"], capture_output=True) == "hello"
|
||||
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_environment():
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
assert (
|
||||
container.call(
|
||||
["sh", "-c", "echo $TEST_VAR"], env={"TEST_VAR": "1"}, capture_output=True
|
||||
@@ -48,14 +48,16 @@ def test_environment():
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_cwd():
|
||||
with DockerContainer(DEFAULT_IMAGE, cwd="/cibuildwheel/working_directory") as container:
|
||||
with DockerContainer(
|
||||
docker_image=DEFAULT_IMAGE, cwd="/cibuildwheel/working_directory"
|
||||
) as container:
|
||||
assert container.call(["pwd"], capture_output=True) == "/cibuildwheel/working_directory\n"
|
||||
assert container.call(["pwd"], capture_output=True, cwd="/opt") == "/opt\n"
|
||||
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_container_removed():
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
docker_containers_listing = subprocess.run(
|
||||
"docker container ls",
|
||||
shell=True,
|
||||
@@ -88,7 +90,7 @@ def test_large_environment():
|
||||
"d": "0" * long_env_var_length,
|
||||
}
|
||||
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
# check the length of d
|
||||
assert (
|
||||
container.call(["sh", "-c", "echo ${#d}"], env=large_environment, capture_output=True)
|
||||
@@ -98,7 +100,7 @@ def test_large_environment():
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_binary_output():
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
# note: the below embedded snippets are in python2
|
||||
|
||||
# check that we can pass though arbitrary binary data without erroring
|
||||
@@ -149,7 +151,7 @@ def test_binary_output():
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_file_operations(tmp_path: Path):
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
# test copying a file in
|
||||
test_binary_data = bytes(random.randrange(256) for _ in range(1000))
|
||||
original_test_file = tmp_path / "test.dat"
|
||||
@@ -165,7 +167,7 @@ def test_file_operations(tmp_path: Path):
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_dir_operations(tmp_path: Path):
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
test_binary_data = bytes(random.randrange(256) for _ in range(1000))
|
||||
original_test_file = tmp_path / "test.dat"
|
||||
original_test_file.write_bytes(test_binary_data)
|
||||
@@ -195,6 +197,6 @@ def test_dir_operations(tmp_path: Path):
|
||||
|
||||
@pytest.mark.docker
|
||||
def test_environment_executor():
|
||||
with DockerContainer(DEFAULT_IMAGE) as container:
|
||||
with DockerContainer(docker_image=DEFAULT_IMAGE) as container:
|
||||
assignment = EnvironmentAssignment("TEST=$(echo 42)")
|
||||
assert assignment.evaluated_value({}, container.environment_executor) == "42"
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
|
||||
import cibuildwheel.docker_container
|
||||
import cibuildwheel.linux
|
||||
from cibuildwheel.options import Options
|
||||
|
||||
from .utils import get_default_command_line_arguments
|
||||
|
||||
|
||||
def test_linux_container_split(tmp_path: Path, monkeypatch):
|
||||
"""
|
||||
Tests splitting linux builds by docker image and before_all
|
||||
"""
|
||||
|
||||
args = get_default_command_line_arguments()
|
||||
args.platform = "linux"
|
||||
|
||||
(tmp_path / "pyproject.toml").write_text(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
manylinux-x86_64-image = "normal_docker_image"
|
||||
manylinux-i686-image = "normal_docker_image"
|
||||
build = "*-manylinux_x86_64"
|
||||
skip = "pp*"
|
||||
archs = "x86_64 i686"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp{38,39,310}-*"
|
||||
manylinux-x86_64-image = "other_docker_image"
|
||||
manylinux-i686-image = "other_docker_image"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp39-*"
|
||||
before-all = "echo 'a cp39-only command'"
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
monkeypatch.chdir(tmp_path)
|
||||
options = Options("linux", command_line_arguments=args)
|
||||
|
||||
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
|
||||
def identifiers(step):
|
||||
return [c.identifier for c in step.platform_configs]
|
||||
|
||||
def before_alls(step):
|
||||
return [options.build_options(c.identifier).before_all for c in step.platform_configs]
|
||||
|
||||
pprint(build_steps)
|
||||
|
||||
assert build_steps[0].docker_image == "normal_docker_image"
|
||||
assert identifiers(build_steps[0]) == ["cp36-manylinux_x86_64", "cp37-manylinux_x86_64"]
|
||||
assert before_alls(build_steps[0]) == ["", ""]
|
||||
|
||||
assert build_steps[1].docker_image == "other_docker_image"
|
||||
assert identifiers(build_steps[1]) == ["cp38-manylinux_x86_64", "cp310-manylinux_x86_64"]
|
||||
assert before_alls(build_steps[1]) == ["", ""]
|
||||
|
||||
assert build_steps[2].docker_image == "other_docker_image"
|
||||
assert identifiers(build_steps[2]) == ["cp39-manylinux_x86_64"]
|
||||
assert before_alls(build_steps[2]) == ["echo 'a cp39-only command'"]
|
||||
@@ -15,9 +15,6 @@ class ArgsInterceptor:
|
||||
self.kwargs = kwargs
|
||||
|
||||
|
||||
MOCK_PACKAGE_DIR = Path("some_package_dir")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_protection(monkeypatch):
|
||||
"""
|
||||
@@ -41,22 +38,8 @@ def mock_protection(monkeypatch):
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fake_package_dir(monkeypatch):
|
||||
"""
|
||||
Monkey-patch enough for the main() function to run
|
||||
"""
|
||||
real_path_exists = Path.exists
|
||||
|
||||
def mock_path_exists(path):
|
||||
if path == MOCK_PACKAGE_DIR / "setup.py":
|
||||
return True
|
||||
else:
|
||||
return real_path_exists(path)
|
||||
|
||||
args = ["cibuildwheel", str(MOCK_PACKAGE_DIR)]
|
||||
monkeypatch.setattr(Path, "exists", mock_path_exists)
|
||||
monkeypatch.setattr(sys, "argv", args)
|
||||
return args
|
||||
def fake_package_dir_autouse(fake_package_dir):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
@@ -3,10 +3,12 @@ from fnmatch import fnmatch
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import tomli
|
||||
|
||||
from cibuildwheel.__main__ import main
|
||||
from cibuildwheel.environment import ParsedEnvironment
|
||||
from cibuildwheel.util import BuildSelector
|
||||
from cibuildwheel.options import BuildOptions, _get_pinned_docker_images
|
||||
from cibuildwheel.util import BuildSelector, resources_dir
|
||||
|
||||
# CIBW_PLATFORM is tested in main_platform_test.py
|
||||
|
||||
@@ -18,13 +20,13 @@ def test_output_dir(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == OUTPUT_DIR
|
||||
assert intercepted_build_args.args[0].globals.output_dir == OUTPUT_DIR
|
||||
|
||||
|
||||
def test_output_dir_default(platform, intercepted_build_args, monkeypatch):
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == Path("wheelhouse")
|
||||
assert intercepted_build_args.args[0].globals.output_dir == Path("wheelhouse")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("also_set_environment", [False, True])
|
||||
@@ -37,7 +39,7 @@ def test_output_dir_argument(also_set_environment, platform, intercepted_build_a
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == OUTPUT_DIR
|
||||
assert intercepted_build_args.args[0].globals.output_dir == OUTPUT_DIR
|
||||
|
||||
|
||||
def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty):
|
||||
@@ -49,7 +51,7 @@ def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_emp
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].general_build_options.build_selector
|
||||
intercepted_build_selector = intercepted_build_args.args[0].globals.build_selector
|
||||
assert isinstance(intercepted_build_selector, BuildSelector)
|
||||
assert intercepted_build_selector("build24-this")
|
||||
assert not intercepted_build_selector("skip65-that")
|
||||
@@ -97,13 +99,15 @@ def test_manylinux_images(
|
||||
|
||||
main()
|
||||
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
if platform == "linux":
|
||||
assert fnmatch(
|
||||
intercepted_build_args.args[0].general_build_options.manylinux_images[architecture],
|
||||
build_options.manylinux_images[architecture],
|
||||
full_image,
|
||||
)
|
||||
else:
|
||||
assert intercepted_build_args.args[0].general_build_options.manylinux_images is None
|
||||
assert build_options.manylinux_images is None
|
||||
|
||||
|
||||
def get_default_repair_command(platform):
|
||||
@@ -131,8 +135,10 @@ def test_repair_command(
|
||||
|
||||
main()
|
||||
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
expected_repair = repair_command or get_default_repair_command(platform)
|
||||
assert intercepted_build_args.args[0].general_build_options.repair_command == expected_repair
|
||||
assert build_options.repair_command == expected_repair
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -150,7 +156,9 @@ def test_environment(environment, platform_specific, platform, intercepted_build
|
||||
|
||||
main()
|
||||
|
||||
intercepted_environment = intercepted_build_args.args[0].general_build_options.environment
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
intercepted_environment = build_options.environment
|
||||
|
||||
assert isinstance(intercepted_environment, ParsedEnvironment)
|
||||
assert intercepted_environment.as_dictionary(prev_environment={}) == environment
|
||||
|
||||
@@ -169,10 +177,9 @@ def test_test_requires(
|
||||
|
||||
main()
|
||||
|
||||
assert (
|
||||
intercepted_build_args.args[0].general_build_options.test_requires
|
||||
== (test_requires or "").split()
|
||||
)
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.test_requires == (test_requires or "").split()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_extras", [None, "extras"])
|
||||
@@ -187,9 +194,9 @@ def test_test_extras(test_extras, platform_specific, platform, intercepted_build
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.test_extras == (
|
||||
"[" + test_extras + "]" if test_extras else ""
|
||||
)
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.test_extras == ("[" + test_extras + "]" if test_extras else "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_command", [None, "test --command"])
|
||||
@@ -206,7 +213,9 @@ def test_test_command(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.test_command == (test_command or "")
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.test_command == (test_command or "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("before_build", [None, "before --build"])
|
||||
@@ -223,7 +232,8 @@ def test_before_build(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.before_build == (before_build or "")
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
assert build_options.before_build == (before_build or "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("build_verbosity", [None, 0, 2, -2, 4, -4])
|
||||
@@ -239,11 +249,10 @@ def test_build_verbosity(
|
||||
monkeypatch.setenv("CIBW_BUILD_VERBOSITY", str(build_verbosity))
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
expected_verbosity = max(-3, min(3, int(build_verbosity or 0)))
|
||||
assert (
|
||||
intercepted_build_args.args[0].general_build_options.build_verbosity == expected_verbosity
|
||||
)
|
||||
assert build_options.build_verbosity == expected_verbosity
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -294,4 +303,36 @@ def test_before_all(before_all, platform_specific, platform, intercepted_build_a
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.before_all == (before_all or "")
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.before_all == (before_all or "")
|
||||
|
||||
|
||||
def test_defaults(platform, intercepted_build_args):
|
||||
main()
|
||||
|
||||
build_options: BuildOptions = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
defaults_config_path = resources_dir / "defaults.toml"
|
||||
with defaults_config_path.open("rb") as f:
|
||||
defaults_toml = tomli.load(f)
|
||||
|
||||
root_defaults = defaults_toml["tool"]["cibuildwheel"]
|
||||
platform_defaults = defaults_toml["tool"]["cibuildwheel"][platform]
|
||||
|
||||
defaults = {}
|
||||
defaults.update(root_defaults)
|
||||
defaults.update(platform_defaults)
|
||||
|
||||
# test a few options
|
||||
assert build_options.before_all == defaults["before-all"]
|
||||
repair_wheel_default = defaults["repair-wheel-command"]
|
||||
if isinstance(repair_wheel_default, list):
|
||||
repair_wheel_default = " && ".join(repair_wheel_default)
|
||||
assert build_options.repair_command == repair_wheel_default
|
||||
assert build_options.build_frontend == defaults["build-frontend"]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.manylinux_images
|
||||
pinned_images = _get_pinned_docker_images()
|
||||
default_x86_64_image = pinned_images["x86_64"][defaults["manylinux-x86_64-image"]]
|
||||
assert build_options.manylinux_images["x86_64"] == default_x86_64_image
|
||||
|
||||
@@ -5,7 +5,7 @@ import pytest
|
||||
from cibuildwheel.__main__ import main
|
||||
from cibuildwheel.architecture import Architecture
|
||||
|
||||
from .conftest import MOCK_PACKAGE_DIR
|
||||
from ..conftest import MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_unknown_platform_non_ci(monkeypatch, capsys):
|
||||
@@ -58,26 +58,29 @@ def test_platform_argument(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
assert options.globals.package_dir == MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_platform_environment(platform, intercepted_build_args, monkeypatch):
|
||||
main()
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR
|
||||
assert options.globals.package_dir == MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_archs_default(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {Architecture.x86_64, Architecture.i686}
|
||||
assert options.globals.architectures == {Architecture.x86_64, Architecture.i686}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.AMD64, Architecture.x86}
|
||||
assert options.globals.architectures == {Architecture.AMD64, Architecture.x86}
|
||||
else:
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_env_var", [False, True])
|
||||
@@ -96,8 +99,8 @@ def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_v
|
||||
|
||||
else:
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
assert build_options.architectures == {Architecture.ppc64le}
|
||||
options = intercepted_build_args.args[0]
|
||||
assert options.globals.architectures == {Architecture.ppc64le}
|
||||
|
||||
|
||||
def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
|
||||
@@ -107,38 +110,38 @@ def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS_MACOS", "x86_64")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {Architecture.ppc64le}
|
||||
assert options.globals.architectures == {Architecture.ppc64le}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.x86}
|
||||
assert options.globals.architectures == {Architecture.x86}
|
||||
elif platform == "macos":
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
|
||||
|
||||
def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS", "native")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform in {"linux", "macos"}:
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.AMD64}
|
||||
assert options.globals.architectures == {Architecture.AMD64}
|
||||
|
||||
|
||||
def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS", "auto64")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform in {"linux", "macos"}:
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.AMD64}
|
||||
assert options.globals.architectures == {Architecture.AMD64}
|
||||
|
||||
|
||||
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
|
||||
@@ -152,22 +155,22 @@ def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
|
||||
else:
|
||||
main()
|
||||
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {Architecture.i686}
|
||||
assert options.globals.architectures == {Architecture.i686}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.x86}
|
||||
assert options.globals.architectures == {Architecture.x86}
|
||||
|
||||
|
||||
def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS", "all")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {
|
||||
assert options.globals.architectures == {
|
||||
Architecture.x86_64,
|
||||
Architecture.i686,
|
||||
Architecture.aarch64,
|
||||
@@ -175,9 +178,9 @@ def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
|
||||
Architecture.s390x,
|
||||
}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.x86, Architecture.AMD64}
|
||||
assert options.globals.architectures == {Architecture.x86, Architecture.AMD64}
|
||||
elif platform == "macos":
|
||||
assert build_options.architectures == {
|
||||
assert options.globals.architectures == {
|
||||
Architecture.x86_64,
|
||||
Architecture.arm64,
|
||||
Architecture.universal2,
|
||||
|
||||
@@ -27,7 +27,8 @@ def test_no_override(platform, monkeypatch, intercepted_build_args):
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector("cp39-win32")
|
||||
assert intercepted_build_selector("cp36-win32")
|
||||
@@ -40,7 +41,8 @@ def test_override_env(platform, monkeypatch, intercepted_build_args):
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
||||
|
||||
@@ -61,7 +63,8 @@ def test_override_setup_cfg(platform, monkeypatch, intercepted_build_args, fake_
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
||||
|
||||
@@ -82,7 +85,8 @@ def test_override_pyproject_toml(platform, monkeypatch, intercepted_build_args,
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
||||
|
||||
@@ -107,7 +111,8 @@ def test_override_setup_py_simple(platform, monkeypatch, intercepted_build_args,
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.7")
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import platform as platform_module
|
||||
import subprocess
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import cast
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from cibuildwheel import linux, util
|
||||
from cibuildwheel.__main__ import main
|
||||
|
||||
ALL_IDS = {"cp36", "cp37", "cp38", "cp39", "cp310", "pp37"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_build_docker(monkeypatch):
|
||||
def fail_on_call(*args, **kwargs):
|
||||
raise RuntimeError("This should never be called")
|
||||
|
||||
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)
|
||||
monkeypatch.setattr(util, "download", fail_on_call)
|
||||
monkeypatch.setattr("cibuildwheel.linux.DockerContainer", ignore_context_call)
|
||||
|
||||
monkeypatch.setattr("cibuildwheel.linux.build_on_docker", mock.Mock(spec=linux.build_on_docker))
|
||||
monkeypatch.setattr("cibuildwheel.util.print_new_wheels", ignore_context_call)
|
||||
|
||||
|
||||
def test_build_default_launches(mock_build_docker, fake_package_dir):
|
||||
|
||||
main(["--platform=linux"])
|
||||
build_on_docker = cast(mock.Mock, linux.build_on_docker)
|
||||
|
||||
assert build_on_docker.call_count == 4
|
||||
|
||||
# In Python 3.8+, this can be simplified to [0].kwargs
|
||||
kwargs = build_on_docker.call_args_list[0][1]
|
||||
assert "quay.io/pypa/manylinux2010_x86_64" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert not kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {f"{x}-manylinux_x86_64" for x in ALL_IDS}
|
||||
|
||||
kwargs = build_on_docker.call_args_list[1][1]
|
||||
assert "quay.io/pypa/manylinux2010_i686" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {f"{x}-manylinux_i686" for x in ALL_IDS}
|
||||
|
||||
kwargs = build_on_docker.call_args_list[2][1]
|
||||
assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert not kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {
|
||||
f"{x}-musllinux_x86_64" for x in ALL_IDS for x in ALL_IDS if "pp" not in x
|
||||
}
|
||||
|
||||
kwargs = build_on_docker.call_args_list[3][1]
|
||||
assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {f"{x}-musllinux_i686" for x in ALL_IDS if "pp" not in x}
|
||||
|
||||
|
||||
def test_build_with_override_launches(mock_build_docker, monkeypatch, tmp_path):
|
||||
pkg_dir = tmp_path / "cibw_package"
|
||||
pkg_dir.mkdir()
|
||||
|
||||
cibw_toml = pkg_dir / "pyproject.toml"
|
||||
cibw_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
manylinux-x86_64-image = "manylinux2014"
|
||||
|
||||
# Before Python 3.10, manylinux2010 is the most compatible
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp3?-*"
|
||||
manylinux-x86_64-image = "manylinux2010"
|
||||
manylinux-i686-image = "manylinux2010"
|
||||
|
||||
[[tool.cibuildwheel.overrides]]
|
||||
select = "cp36-manylinux_x86_64"
|
||||
before-all = "true"
|
||||
"""
|
||||
)
|
||||
|
||||
monkeypatch.chdir(pkg_dir)
|
||||
main(["--platform=linux"])
|
||||
build_on_docker = cast(mock.Mock, linux.build_on_docker)
|
||||
|
||||
assert build_on_docker.call_count == 6
|
||||
|
||||
kwargs = build_on_docker.call_args_list[0][1]
|
||||
assert "quay.io/pypa/manylinux2010_x86_64" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert not kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {"cp36-manylinux_x86_64"}
|
||||
assert kwargs["options"].build_options("cp36-manylinux_x86_64").before_all == "true"
|
||||
|
||||
kwargs = build_on_docker.call_args_list[1][1]
|
||||
assert "quay.io/pypa/manylinux2010_x86_64" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert not kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {f"{x}-manylinux_x86_64" for x in ALL_IDS - {"cp36", "cp310", "pp37"}}
|
||||
assert kwargs["options"].build_options("cp37-manylinux_x86_64").before_all == ""
|
||||
|
||||
kwargs = build_on_docker.call_args_list[2][1]
|
||||
assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert not kwargs["docker"]["simulate_32_bit"]
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {"cp310-manylinux_x86_64", "pp37-manylinux_x86_64"}
|
||||
|
||||
kwargs = build_on_docker.call_args_list[3][1]
|
||||
assert "quay.io/pypa/manylinux2010_i686" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {f"{x}-manylinux_i686" for x in ALL_IDS}
|
||||
|
||||
kwargs = build_on_docker.call_args_list[4][1]
|
||||
assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert not kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {
|
||||
f"{x}-musllinux_x86_64" for x in ALL_IDS for x in ALL_IDS if "pp" not in x
|
||||
}
|
||||
|
||||
kwargs = build_on_docker.call_args_list[5][1]
|
||||
assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["docker"]["docker_image"]
|
||||
assert kwargs["docker"]["cwd"] == Path("/project")
|
||||
assert kwargs["docker"]["simulate_32_bit"]
|
||||
|
||||
identifiers = {x.identifier for x in kwargs["platform_configs"]}
|
||||
assert identifiers == {f"{x}-musllinux_i686" for x in ALL_IDS if "pp" not in x}
|
||||
@@ -1,9 +1,10 @@
|
||||
from pathlib import Path
|
||||
import platform as platform_module
|
||||
|
||||
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
|
||||
from cibuildwheel.options import Options, _get_pinned_docker_images
|
||||
|
||||
from .utils import get_default_command_line_arguments
|
||||
|
||||
PYPROJECT_1 = """
|
||||
[tool.cibuildwheel]
|
||||
@@ -24,38 +25,44 @@ manylinux-x86_64-image = "manylinux2014"
|
||||
"""
|
||||
|
||||
|
||||
def test_all_build_options_1(tmp_path):
|
||||
def test_options_1(tmp_path, monkeypatch):
|
||||
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
|
||||
)
|
||||
args = get_default_command_line_arguments()
|
||||
args.package_dir = str(tmp_path)
|
||||
|
||||
monkeypatch.setattr(platform_module, "machine", lambda: "x86_64")
|
||||
|
||||
options = Options(platform="linux", command_line_arguments=args)
|
||||
|
||||
identifiers = get_build_identifiers(
|
||||
"linux", all_build_options.build_selector, all_build_options.architectures
|
||||
platform="linux",
|
||||
build_selector=options.globals.build_selector,
|
||||
architectures=options.globals.architectures,
|
||||
)
|
||||
|
||||
build_options = AllBuildOptions(all_build_options, build_options_by_selector, identifiers)
|
||||
|
||||
override_display = """\
|
||||
test_command:
|
||||
*: 'pyproject'
|
||||
cp37*: 'pyproject-override'"""
|
||||
test_command: 'pyproject'
|
||||
cp37-manylinux_x86_64: 'pyproject-override'"""
|
||||
|
||||
assert override_display in str(build_options)
|
||||
print(options.summary(identifiers))
|
||||
|
||||
assert build_options.environment == parse_environment('FOO="BAR"')
|
||||
assert override_display in options.summary(identifiers)
|
||||
|
||||
default_build_options = options.build_options(identifier=None)
|
||||
|
||||
assert default_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"]
|
||||
local = options.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"]
|
||||
local = options.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"]
|
||||
@@ -1,6 +1,8 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from cibuildwheel.options import ConfigOptionError, ConfigOptions, _dig_first
|
||||
from cibuildwheel.options import ConfigOptionError, OptionsReader, _dig_first
|
||||
|
||||
PYPROJECT_1 = """
|
||||
[tool.cibuildwheel]
|
||||
@@ -28,39 +30,43 @@ def platform(request):
|
||||
|
||||
@pytest.mark.parametrize("fname", ["pyproject.toml", "cibuildwheel.toml"])
|
||||
def test_simple_settings(tmp_path, platform, fname):
|
||||
with tmp_path.joinpath(fname).open("w") as f:
|
||||
f.write(PYPROJECT_1)
|
||||
config_file_path: Path = tmp_path / fname
|
||||
config_file_path.write_text(PYPROJECT_1)
|
||||
|
||||
options = ConfigOptions(tmp_path, f"{{package}}/{fname}", platform=platform)
|
||||
options_reader = OptionsReader(config_file_path, platform=platform)
|
||||
|
||||
assert options("build", env_plat=False, sep=" ") == "cp39*"
|
||||
assert options_reader.get("build", env_plat=False, sep=" ") == "cp39*"
|
||||
|
||||
assert options("test-command") == "pyproject"
|
||||
assert options("archs", sep=" ") == "auto"
|
||||
assert options_reader.get("test-command") == "pyproject"
|
||||
assert options_reader.get("archs", sep=" ") == "auto"
|
||||
assert (
|
||||
options("test-requires", sep=" ")
|
||||
options_reader.get("test-requires", sep=" ")
|
||||
== {"windows": "something", "macos": "else", "linux": "other many"}[platform]
|
||||
)
|
||||
|
||||
# Also testing options for support for both lists and tables
|
||||
assert (
|
||||
options("environment", table={"item": '{k}="{v}"', "sep": " "}) == 'THING="OTHER" FOO="BAR"'
|
||||
)
|
||||
assert (
|
||||
options("environment", sep="x", table={"item": '{k}="{v}"', "sep": " "})
|
||||
options_reader.get("environment", table={"item": '{k}="{v}"', "sep": " "})
|
||||
== 'THING="OTHER" FOO="BAR"'
|
||||
)
|
||||
assert options("test-extras", sep=",") == "one,two"
|
||||
assert options("test-extras", sep=",", table={"item": '{k}="{v}"', "sep": " "}) == "one,two"
|
||||
assert (
|
||||
options_reader.get("environment", sep="x", table={"item": '{k}="{v}"', "sep": " "})
|
||||
== 'THING="OTHER" FOO="BAR"'
|
||||
)
|
||||
assert options_reader.get("test-extras", sep=",") == "one,two"
|
||||
assert (
|
||||
options_reader.get("test-extras", sep=",", table={"item": '{k}="{v}"', "sep": " "})
|
||||
== "one,two"
|
||||
)
|
||||
|
||||
assert options("manylinux-x86_64-image") == "manylinux1"
|
||||
assert options("manylinux-i686-image") == "manylinux2010"
|
||||
assert options_reader.get("manylinux-x86_64-image") == "manylinux1"
|
||||
assert options_reader.get("manylinux-i686-image") == "manylinux2010"
|
||||
|
||||
with pytest.raises(ConfigOptionError):
|
||||
options("environment", sep=" ")
|
||||
options_reader.get("environment", sep=" ")
|
||||
|
||||
with pytest.raises(ConfigOptionError):
|
||||
options("test-extras", table={"item": '{k}="{v}"', "sep": " "})
|
||||
options_reader.get("test-extras", table={"item": '{k}="{v}"', "sep": " "})
|
||||
|
||||
|
||||
def test_envvar_override(tmp_path, platform, monkeypatch):
|
||||
@@ -70,44 +76,46 @@ def test_envvar_override(tmp_path, platform, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_TEST_REQUIRES", "docs")
|
||||
monkeypatch.setenv("CIBW_TEST_REQUIRES_LINUX", "scod")
|
||||
|
||||
with tmp_path.joinpath("pyproject.toml").open("w") as f:
|
||||
f.write(PYPROJECT_1)
|
||||
config_file_path: Path = tmp_path / "pyproject.toml"
|
||||
config_file_path.write_text(PYPROJECT_1)
|
||||
|
||||
options = ConfigOptions(tmp_path, platform=platform)
|
||||
options_reader = OptionsReader(config_file_path, platform=platform)
|
||||
|
||||
assert options("archs", sep=" ") == "auto"
|
||||
assert options_reader.get("archs", sep=" ") == "auto"
|
||||
|
||||
assert options("build", sep=" ") == "cp38*"
|
||||
assert options("manylinux-x86_64-image") == "manylinux2014"
|
||||
assert options("manylinux-i686-image") == "manylinux2010"
|
||||
assert options_reader.get("build", sep=" ") == "cp38*"
|
||||
assert options_reader.get("manylinux-x86_64-image") == "manylinux2014"
|
||||
assert options_reader.get("manylinux-i686-image") == "manylinux2010"
|
||||
|
||||
assert (
|
||||
options("test-requires", sep=" ")
|
||||
options_reader.get("test-requires", sep=" ")
|
||||
== {"windows": "docs", "macos": "docs", "linux": "scod"}[platform]
|
||||
)
|
||||
assert options("test-command") == "mytest"
|
||||
assert options_reader.get("test-command") == "mytest"
|
||||
|
||||
|
||||
def test_project_global_override_default_platform(tmp_path, platform):
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
repair-wheel-command = "repair-project-global"
|
||||
"""
|
||||
)
|
||||
options = ConfigOptions(tmp_path, platform=platform)
|
||||
assert options("repair-wheel-command") == "repair-project-global"
|
||||
options_reader = OptionsReader(pyproject_toml, platform=platform)
|
||||
assert options_reader.get("repair-wheel-command") == "repair-project-global"
|
||||
|
||||
|
||||
def test_env_global_override_default_platform(tmp_path, platform, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_REPAIR_WHEEL_COMMAND", "repair-env-global")
|
||||
options = ConfigOptions(tmp_path, platform=platform)
|
||||
assert options("repair-wheel-command") == "repair-env-global"
|
||||
options_reader = OptionsReader(platform=platform)
|
||||
assert options_reader.get("repair-wheel-command") == "repair-env-global"
|
||||
|
||||
|
||||
def test_env_global_override_project_platform(tmp_path, platform, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_REPAIR_WHEEL_COMMAND", "repair-env-global")
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel.linux]
|
||||
repair-wheel-command = "repair-project-linux"
|
||||
@@ -117,12 +125,13 @@ repair-wheel-command = "repair-project-windows"
|
||||
repair-wheel-command = "repair-project-macos"
|
||||
"""
|
||||
)
|
||||
options = ConfigOptions(tmp_path, platform=platform)
|
||||
assert options("repair-wheel-command") == "repair-env-global"
|
||||
options_reader = OptionsReader(pyproject_toml, platform=platform)
|
||||
assert options_reader.get("repair-wheel-command") == "repair-env-global"
|
||||
|
||||
|
||||
def test_global_platform_order(tmp_path, platform):
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel.linux]
|
||||
repair-wheel-command = "repair-project-linux"
|
||||
@@ -134,14 +143,15 @@ repair-wheel-command = "repair-project-macos"
|
||||
repair-wheel-command = "repair-project-global"
|
||||
"""
|
||||
)
|
||||
options = ConfigOptions(tmp_path, platform=platform)
|
||||
assert options("repair-wheel-command") == f"repair-project-{platform}"
|
||||
options_reader = OptionsReader(pyproject_toml, platform=platform)
|
||||
assert options_reader.get("repair-wheel-command") == f"repair-project-{platform}"
|
||||
|
||||
|
||||
def test_unexpected_key(tmp_path):
|
||||
# Note that platform contents are only checked when running
|
||||
# for that platform.
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
repairs-wheel-command = "repair-project-linux"
|
||||
@@ -149,49 +159,53 @@ repairs-wheel-command = "repair-project-linux"
|
||||
)
|
||||
|
||||
with pytest.raises(ConfigOptionError):
|
||||
ConfigOptions(tmp_path, platform="linux")
|
||||
OptionsReader(pyproject_toml, platform="linux")
|
||||
|
||||
|
||||
def test_unexpected_table(tmp_path):
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel.linus]
|
||||
repair-wheel-command = "repair-project-linux"
|
||||
"""
|
||||
)
|
||||
with pytest.raises(ConfigOptionError):
|
||||
ConfigOptions(tmp_path, platform="linux")
|
||||
OptionsReader(pyproject_toml, platform="linux")
|
||||
|
||||
|
||||
def test_unsupported_join(tmp_path):
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
build = ["1", "2"]
|
||||
"""
|
||||
)
|
||||
options = ConfigOptions(tmp_path, platform="linux")
|
||||
options_reader = OptionsReader(pyproject_toml, platform="linux")
|
||||
|
||||
assert "1, 2" == options("build", sep=", ")
|
||||
assert "1, 2" == options_reader.get("build", sep=", ")
|
||||
with pytest.raises(ConfigOptionError):
|
||||
options("build")
|
||||
options_reader.get("build")
|
||||
|
||||
|
||||
def test_disallowed_a(tmp_path):
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel.windows]
|
||||
manylinux-x86_64-image = "manylinux1"
|
||||
"""
|
||||
)
|
||||
disallow = {"windows": {"manylinux-x86_64-image"}}
|
||||
ConfigOptions(tmp_path, platform="linux", disallow=disallow)
|
||||
OptionsReader(pyproject_toml, platform="linux", disallow=disallow)
|
||||
with pytest.raises(ConfigOptionError):
|
||||
ConfigOptions(tmp_path, platform="windows", disallow=disallow)
|
||||
OptionsReader(pyproject_toml, platform="windows", disallow=disallow)
|
||||
|
||||
|
||||
def test_environment_override_empty(tmp_path, monkeypatch):
|
||||
tmp_path.joinpath("pyproject.toml").write_text(
|
||||
pyproject_toml = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(
|
||||
"""
|
||||
[tool.cibuildwheel]
|
||||
manylinux-i686-image = "manylinux1"
|
||||
@@ -202,15 +216,15 @@ manylinux-x86_64-image = ""
|
||||
monkeypatch.setenv("CIBW_MANYLINUX_I686_IMAGE", "")
|
||||
monkeypatch.setenv("CIBW_MANYLINUX_AARCH64_IMAGE", "manylinux1")
|
||||
|
||||
options = ConfigOptions(tmp_path, platform="linux")
|
||||
options_reader = OptionsReader(pyproject_toml, platform="linux")
|
||||
|
||||
assert options("manylinux-x86_64-image") == ""
|
||||
assert options("manylinux-i686-image") == ""
|
||||
assert options("manylinux-aarch64-image") == "manylinux1"
|
||||
assert options_reader.get("manylinux-x86_64-image") == ""
|
||||
assert options_reader.get("manylinux-i686-image") == ""
|
||||
assert options_reader.get("manylinux-aarch64-image") == "manylinux1"
|
||||
|
||||
assert options("manylinux-x86_64-image", ignore_empty=True) == "manylinux2010"
|
||||
assert options("manylinux-i686-image", ignore_empty=True) == "manylinux1"
|
||||
assert options("manylinux-aarch64-image", ignore_empty=True) == "manylinux1"
|
||||
assert options_reader.get("manylinux-x86_64-image", ignore_empty=True) == "manylinux2010"
|
||||
assert options_reader.get("manylinux-i686-image", ignore_empty=True) == "manylinux1"
|
||||
assert options_reader.get("manylinux-aarch64-image", ignore_empty=True) == "manylinux1"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ignore_empty", (True, False))
|
||||
@@ -268,26 +282,31 @@ 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)
|
||||
pyproject_toml: Path = tmp_path / "pyproject.toml"
|
||||
pyproject_toml.write_text(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"
|
||||
options_reader = OptionsReader(config_file_path=pyproject_toml, platform=platform)
|
||||
assert options_reader.get("test-command") == "pyproject"
|
||||
|
||||
with options_reader.identifier("random"):
|
||||
assert options_reader.get("test-command") == "pyproject"
|
||||
|
||||
with options_reader.identifier("cp37-something"):
|
||||
assert options_reader.get("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(
|
||||
"""\
|
||||
pyproject_toml: Path = tmp_path / "pyproject.toml"
|
||||
|
||||
pyproject_toml.write_text(
|
||||
"""\
|
||||
[tool.cibuildwheel]
|
||||
build = ["cp38*", "cp37*"]
|
||||
[tool.cibuildwheel.overrides]
|
||||
select = "cp37*"
|
||||
test-command = "pyproject-override"
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
with pytest.raises(ConfigOptionError):
|
||||
ConfigOptions(tmp_path, platform=platform)
|
||||
OptionsReader(config_file_path=pyproject_toml, platform=platform)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from cibuildwheel.options import CommandLineArguments
|
||||
|
||||
|
||||
def get_default_command_line_arguments() -> CommandLineArguments:
|
||||
defaults = CommandLineArguments()
|
||||
|
||||
defaults.platform = "auto"
|
||||
defaults.allow_empty = False
|
||||
defaults.archs = None
|
||||
defaults.config_file = None
|
||||
defaults.output_dir = None
|
||||
defaults.package_dir = "."
|
||||
defaults.prerelease_pythons = False
|
||||
defaults.print_build_identifiers = False
|
||||
|
||||
return defaults
|
||||
Reference in New Issue
Block a user