2026-05-28 00:20:08 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2021-01-31 17:14:15 -05:00
|
|
|
import sys
|
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from packaging.specifiers import SpecifierSet
|
|
|
|
|
|
|
|
|
|
from cibuildwheel.__main__ import main
|
|
|
|
|
|
2026-05-28 00:20:08 +02:00
|
|
|
TYPE_CHECKING = False
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from .conftest import ArgsInterceptor
|
2026-04-01 10:23:02 -04:00
|
|
|
|
2021-01-31 17:14:15 -05:00
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.fixture(autouse=True)
|
2026-04-01 10:23:02 -04:00
|
|
|
def fake_package_dir(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2021-01-31 17:14:15 -05:00
|
|
|
Set up a fake project
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
local_path = tmp_path / "tmp_project"
|
|
|
|
|
local_path.mkdir()
|
|
|
|
|
|
|
|
|
|
local_path.joinpath("setup.py").touch()
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
monkeypatch.setattr(sys, "argv", ["cibuildwheel", str(local_path)])
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
return local_path
|
|
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("platform")
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_no_override(intercepted_build_args: ArgsInterceptor) -> None:
|
2021-01-31 17:14:15 -05:00
|
|
|
main()
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
options = intercepted_build_args.args[0]
|
|
|
|
|
intercepted_build_selector = options.globals.build_selector
|
2021-01-31 17:14:15 -05:00
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
assert intercepted_build_selector("cp39-win32")
|
|
|
|
|
assert intercepted_build_selector("cp36-win32")
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
assert intercepted_build_selector.requires_python is None
|
|
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("platform")
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_override_env(
|
|
|
|
|
monkeypatch: pytest.MonkeyPatch, intercepted_build_args: ArgsInterceptor
|
|
|
|
|
) -> None:
|
2021-05-03 11:45:43 -04:00
|
|
|
monkeypatch.setenv("CIBW_PROJECT_REQUIRES_PYTHON", ">=3.8")
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
options = intercepted_build_args.args[0]
|
|
|
|
|
intercepted_build_selector = options.globals.build_selector
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
assert intercepted_build_selector("cp39-win32")
|
|
|
|
|
assert not intercepted_build_selector("cp36-win32")
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("platform")
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_override_setup_cfg(
|
|
|
|
|
intercepted_build_args: ArgsInterceptor, fake_package_dir: Path
|
|
|
|
|
) -> None:
|
2021-04-30 17:56:34 -04:00
|
|
|
fake_package_dir.joinpath("setup.cfg").write_text(
|
|
|
|
|
textwrap.dedent(
|
|
|
|
|
"""
|
2021-05-02 16:37:38 +02:00
|
|
|
[options]
|
|
|
|
|
python_requires = >=3.8
|
|
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
|
|
|
|
)
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
options = intercepted_build_args.args[0]
|
|
|
|
|
intercepted_build_selector = options.globals.build_selector
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
assert intercepted_build_selector("cp39-win32")
|
|
|
|
|
assert not intercepted_build_selector("cp36-win32")
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("platform")
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_override_pyproject_toml(
|
|
|
|
|
intercepted_build_args: ArgsInterceptor, fake_package_dir: Path
|
|
|
|
|
) -> None:
|
2021-04-30 17:56:34 -04:00
|
|
|
fake_package_dir.joinpath("pyproject.toml").write_text(
|
|
|
|
|
textwrap.dedent(
|
|
|
|
|
"""
|
2021-05-02 16:37:38 +02:00
|
|
|
[project]
|
|
|
|
|
requires-python = ">=3.8"
|
|
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
|
|
|
|
)
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
options = intercepted_build_args.args[0]
|
|
|
|
|
intercepted_build_selector = options.globals.build_selector
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
assert intercepted_build_selector("cp39-win32")
|
|
|
|
|
assert not intercepted_build_selector("cp36-win32")
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
|
2023-01-30 15:53:44 -05:00
|
|
|
@pytest.mark.usefixtures("platform")
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_override_setup_py_simple(
|
|
|
|
|
intercepted_build_args: ArgsInterceptor, fake_package_dir: Path
|
|
|
|
|
) -> None:
|
2021-04-30 17:56:34 -04:00
|
|
|
fake_package_dir.joinpath("setup.py").write_text(
|
|
|
|
|
textwrap.dedent(
|
|
|
|
|
"""
|
2021-05-02 16:37:38 +02:00
|
|
|
from setuptools import setup
|
2021-01-31 17:14:15 -05:00
|
|
|
|
2021-05-02 16:37:38 +02:00
|
|
|
setup(
|
|
|
|
|
name = "other",
|
|
|
|
|
python_requires = ">=3.7",
|
|
|
|
|
)
|
|
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
|
|
|
|
)
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
2021-10-12 02:05:47 +01:00
|
|
|
options = intercepted_build_args.args[0]
|
|
|
|
|
intercepted_build_selector = options.globals.build_selector
|
2021-01-31 17:14:15 -05:00
|
|
|
|
|
|
|
|
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.7")
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
assert intercepted_build_selector("cp39-win32")
|
|
|
|
|
assert not intercepted_build_selector("cp36-win32")
|