chore: refactor cibuildwheel.utils (#2252)

* chore: refactor cibuildwheel.utils

* rework build_frontend extra flags

* ci(fix): use tonistiigi/binfmt:qemu-v8.1.5 image for qemu
This commit is contained in:
Matthieu Darbois
2025-01-27 14:35:56 -05:00
committed by GitHub
parent 318a963cc3
commit b605f8fec8
39 changed files with 1188 additions and 1187 deletions
+3 -4
View File
@@ -5,14 +5,13 @@ import tomllib
from packaging.version import Version
from cibuildwheel.extra import Printable, dump_python_configurations
from cibuildwheel.util import resources_dir
from cibuildwheel.util import resources
def test_compare_configs():
with open(resources_dir / "build-platforms.toml") as f1:
txt = f1.read()
txt = resources.BUILD_PLATFORMS.read_text()
with open(resources_dir / "build-platforms.toml", "rb") as f2:
with resources.BUILD_PLATFORMS.open("rb") as f2:
dict_txt = tomllib.load(f2)
new_txt = dump_python_configurations(dict_txt)
+2 -2
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
from packaging.specifiers import SpecifierSet
from cibuildwheel.util import BuildSelector, EnableGroup
from cibuildwheel.selector import BuildSelector, EnableGroup
def test_build():
@@ -162,7 +162,7 @@ def test_build_free_threaded_python():
def test_testing_selector():
# local import to avoid pytest trying to collect this as a test class!
from cibuildwheel.util import TestSelector
from cibuildwheel.selector import TestSelector
test_selector = TestSelector(skip_config="cp36-*")
+1 -1
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
from pathlib import Path
from cibuildwheel.util import DependencyConstraints
from cibuildwheel.util.packaging import DependencyConstraints
def test_defaults():
+1 -1
View File
@@ -5,7 +5,7 @@ import ssl
import certifi
import pytest
from cibuildwheel.util import download
from cibuildwheel.util.file import download
DOWNLOAD_URL = "https://raw.githubusercontent.com/pypa/cibuildwheel/v1.6.3/requirements-dev.txt"
+1 -1
View File
@@ -5,8 +5,8 @@ from pathlib import Path
import pytest
import setuptools._distutils.util
from cibuildwheel.ci import CIProvider, detect_ci_provider
from cibuildwheel.errors import FatalError
from cibuildwheel.util import CIProvider, detect_ci_provider
from cibuildwheel.windows import PythonConfiguration, setup_setuptools_cross_compile
# monkeypatching os.name is too flaky. E.g. It works on my machine, but fails in pipeline
+4 -3
View File
@@ -8,7 +8,8 @@ from pathlib import Path
import pytest
from cibuildwheel import linux, macos, pyodide, util, windows
from cibuildwheel import __main__, linux, macos, pyodide, windows
from cibuildwheel.util import file
class ArgsInterceptor:
@@ -38,7 +39,7 @@ def mock_protection(monkeypatch):
pass
monkeypatch.setattr(subprocess, "Popen", fail_on_call)
monkeypatch.setattr(util, "download", fail_on_call)
monkeypatch.setattr(file, "download", fail_on_call)
monkeypatch.setattr(windows, "build", fail_on_call)
monkeypatch.setattr(linux, "build", fail_on_call)
monkeypatch.setattr(macos, "build", fail_on_call)
@@ -58,7 +59,7 @@ def disable_print_wheels(monkeypatch):
def empty_cm(*args, **kwargs):
yield
monkeypatch.setattr(util, "print_new_wheels", empty_cm)
monkeypatch.setattr(__main__, "print_new_wheels", empty_cm)
@pytest.fixture
+6 -5
View File
@@ -9,8 +9,10 @@ import pytest
from cibuildwheel.__main__ import main
from cibuildwheel.environment import ParsedEnvironment
from cibuildwheel.frontend import _split_config_settings
from cibuildwheel.options import BuildOptions, _get_pinned_container_images
from cibuildwheel.util import BuildSelector, EnableGroup, resources_dir, split_config_settings
from cibuildwheel.selector import BuildSelector, EnableGroup
from cibuildwheel.util import resources
# CIBW_PLATFORM is tested in main_platform_test.py
@@ -281,13 +283,13 @@ def test_config_settings(platform_specific, platform, intercepted_build_args, mo
assert build_options.config_settings == config_settings
assert split_config_settings(config_settings, "build") == [
assert _split_config_settings(config_settings, "build") == [
"--config-setting=setting=value",
"--config-setting=setting=value2",
"--config-setting=other=something else",
]
assert split_config_settings(config_settings, "pip") == [
assert _split_config_settings(config_settings, "pip") == [
"--config-settings=setting=value",
"--config-settings=setting=value2",
"--config-settings=other=something else",
@@ -411,8 +413,7 @@ 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:
with resources.DEFAULTS.open("rb") as f:
defaults_toml = tomllib.load(f)
root_defaults = defaults_toml["tool"]["cibuildwheel"]
+1 -1
View File
@@ -6,7 +6,7 @@ import pytest
from cibuildwheel.__main__ import main
from cibuildwheel.architecture import Architecture
from cibuildwheel.util import EnableGroup
from cibuildwheel.selector import EnableGroup
from ..conftest import MOCK_PACKAGE_DIR
+1 -1
View File
@@ -16,6 +16,7 @@ import pytest
import tomli_w
import cibuildwheel.oci_container
from cibuildwheel.ci import CIProvider, detect_ci_provider
from cibuildwheel.environment import EnvironmentAssignmentBash
from cibuildwheel.errors import OCIEngineTooOldError
from cibuildwheel.oci_container import (
@@ -24,7 +25,6 @@ from cibuildwheel.oci_container import (
OCIPlatform,
_check_engine_version,
)
from cibuildwheel.util import CIProvider, detect_ci_provider
# Test utilities
+4 -3
View File
@@ -10,9 +10,10 @@ from unittest import mock
import pytest
from cibuildwheel import linux, util
from cibuildwheel import linux
from cibuildwheel.__main__ import main
from cibuildwheel.oci_container import OCIPlatform
from cibuildwheel.util import file
DEFAULT_IDS = {"cp36", "cp37", "cp38", "cp39", "cp310", "cp311", "cp312", "cp313"}
ALL_IDS = DEFAULT_IDS | {"cp313t", "pp37", "pp38", "pp39", "pp310"}
@@ -39,13 +40,13 @@ def mock_build_container(monkeypatch):
monkeypatch.setattr(subprocess, "Popen", fail_on_call)
monkeypatch.setattr(subprocess, "run", ignore_call)
monkeypatch.setattr(util, "download", fail_on_call)
monkeypatch.setattr(file, "download", fail_on_call)
monkeypatch.setattr("cibuildwheel.linux.OCIContainer", ignore_context_call)
monkeypatch.setattr(
"cibuildwheel.linux.build_in_container", mock.Mock(spec=linux.build_in_container)
)
monkeypatch.setattr("cibuildwheel.util.print_new_wheels", ignore_context_call)
monkeypatch.setattr("cibuildwheel.__main__.print_new_wheels", ignore_context_call)
@pytest.mark.usefixtures("mock_build_container", "fake_package_dir")
+1 -1
View File
@@ -15,7 +15,7 @@ from cibuildwheel.options import (
Options,
_get_pinned_container_images,
)
from cibuildwheel.util import EnableGroup
from cibuildwheel.selector import EnableGroup
PYPROJECT_1 = """
[tool.cibuildwheel]
+4 -4
View File
@@ -7,15 +7,15 @@ from unittest.mock import Mock, call
import pytest
from cibuildwheel import errors
from cibuildwheel.util import (
from cibuildwheel.ci import fix_ansi_codes_for_github_actions
from cibuildwheel.util.file import copy_test_sources
from cibuildwheel.util.helpers import (
FlexibleVersion,
copy_test_sources,
find_compatible_wheel,
fix_ansi_codes_for_github_actions,
format_safe,
parse_key_value_string,
prepare_command,
)
from cibuildwheel.util.packaging import find_compatible_wheel
def test_format_safe():
+3 -2
View File
@@ -7,12 +7,13 @@ from pathlib import Path
import pytest
import validate_pyproject.api
from cibuildwheel.util import resources
DIR = Path(__file__).parent.resolve()
def test_validate_default_schema():
filepath = DIR.parent / "cibuildwheel/resources/defaults.toml"
with filepath.open("rb") as f:
with resources.DEFAULTS.open("rb") as f:
example = tomllib.load(f)
validator = validate_pyproject.api.Validator()
+1 -1
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
import pytest
from cibuildwheel.util import print_new_wheels
from cibuildwheel.__main__ import print_new_wheels
def test_printout_wheels(tmp_path, capsys):