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,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)
|
||||
|
||||
Reference in New Issue
Block a user