chore: use if TYPE_CHECKING: blocks (#2866)

This commit is contained in:
Matthieu Darbois
2026-05-27 18:20:08 -04:00
committed by GitHub
parent 2380f52783
commit e3e7cc9e07
79 changed files with 566 additions and 168 deletions
+6 -1
View File
@@ -1,3 +1,5 @@
from __future__ import annotations
import platform as platform_module
import shutil
import sys
@@ -6,7 +8,10 @@ import pytest
import cibuildwheel.architecture
from cibuildwheel.architecture import Architecture, arch_synonym
from cibuildwheel.typing import PlatformName
TYPE_CHECKING = False
if TYPE_CHECKING:
from cibuildwheel.typing import PlatformName
@pytest.fixture(
+6 -1
View File
@@ -1,4 +1,5 @@
import contextlib
from __future__ import annotations
import subprocess
from pathlib import Path
from unittest.mock import Mock, patch
@@ -8,6 +9,10 @@ import pytest
from cibuildwheel import errors
from cibuildwheel.audit import needs_audit, run_audit
TYPE_CHECKING = False
if TYPE_CHECKING:
import contextlib
def mock_virtualenv() -> contextlib.AbstractContextManager[Mock]:
return patch(
+6 -1
View File
@@ -1,11 +1,16 @@
from __future__ import annotations
import ssl
from pathlib import Path
import certifi
import pytest
from cibuildwheel.util.file import download
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
DOWNLOAD_URL = "https://cdn.jsdelivr.net/gh/pypa/cibuildwheel@v1.6.3/requirements-dev.txt"
+5 -2
View File
@@ -1,7 +1,7 @@
from __future__ import annotations
import contextlib
import sys
from collections.abc import Generator
from pathlib import Path
import pytest
import setuptools._distutils.util
@@ -11,6 +11,9 @@ from cibuildwheel.errors import FatalError
from cibuildwheel.platforms.windows import PythonConfiguration, setup_setuptools_cross_compile
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Generator
from pathlib import Path
# monkeypatching os.name is too flaky. E.g. It works on my machine, but fails in pipeline
if not sys.platform.startswith("win") and not TYPE_CHECKING:
+9 -4
View File
@@ -1,13 +1,18 @@
import textwrap
from pathlib import Path
from pprint import pprint
from __future__ import annotations
import pytest
import textwrap
from pprint import pprint
import cibuildwheel.platforms.linux
from cibuildwheel.oci_container import OCIContainerEngineConfig
from cibuildwheel.options import CommandLineArguments, Options
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
import pytest
def test_linux_container_split(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""
+6 -1
View File
@@ -1,13 +1,18 @@
from __future__ import annotations
import errno
import shutil
import sys
from pathlib import Path
import pytest
import cibuildwheel.__main__ as main_module
from cibuildwheel.__main__ import main
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
def test_clean_cache_when_cache_exists(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pytest.CaptureFixture[str]
+6 -1
View File
@@ -1,8 +1,9 @@
from __future__ import annotations
import contextlib
import platform as platform_module
import subprocess
import sys
from collections.abc import Generator, Iterator
from pathlib import Path
from typing import Any
@@ -13,6 +14,10 @@ from cibuildwheel.logger import Logger
from cibuildwheel.platforms import android, ios, linux, macos, pyodide, windows
from cibuildwheel.util import file
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Generator, Iterator
class ArgsInterceptor:
def __init__(self) -> None:
+24 -21
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import sys
import tomllib
from collections.abc import Mapping
from fnmatch import fnmatch
from pathlib import Path
@@ -16,6 +17,8 @@ from cibuildwheel.util.packaging import DependencyConstraints
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Mapping
from .conftest import ArgsInterceptor
# CIBW_PLATFORM is tested in main_platform_test.py
@@ -37,7 +40,7 @@ def test_old_free_threaded(
@pytest.mark.usefixtures("platform")
def test_output_dir(
intercepted_build_args: "ArgsInterceptor", monkeypatch: pytest.MonkeyPatch
intercepted_build_args: ArgsInterceptor, monkeypatch: pytest.MonkeyPatch
) -> None:
OUTPUT_DIR = Path("some_output_dir")
@@ -49,7 +52,7 @@ def test_output_dir(
@pytest.mark.usefixtures("platform")
def test_output_dir_default(intercepted_build_args: "ArgsInterceptor") -> None:
def test_output_dir_default(intercepted_build_args: ArgsInterceptor) -> None:
main()
assert intercepted_build_args.args[0].globals.output_dir == Path("wheelhouse").resolve()
@@ -59,7 +62,7 @@ def test_output_dir_default(intercepted_build_args: "ArgsInterceptor") -> None:
@pytest.mark.parametrize("also_set_environment", [False, True])
def test_output_dir_argument(
also_set_environment: bool,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
OUTPUT_DIR = Path("some_output_dir")
@@ -75,7 +78,7 @@ def test_output_dir_argument(
@pytest.mark.usefixtures("platform", "allow_empty")
def test_build_selector(
intercepted_build_args: "ArgsInterceptor", monkeypatch: pytest.MonkeyPatch
intercepted_build_args: ArgsInterceptor, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("CIBW_BUILD", "cp313-*")
monkeypatch.setenv("CIBW_SKIP", "cp39-*")
@@ -191,7 +194,7 @@ def test_manylinux_images(
image: str | None,
full_image: str,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if image is not None:
@@ -230,7 +233,7 @@ def test_repair_command(
repair_command: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if repair_command is not None:
@@ -259,7 +262,7 @@ def test_environment(
environment: Mapping[str, str],
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
env_string = " ".join(f"{k}={v}" for k, v in environment.items())
@@ -284,7 +287,7 @@ def test_test_requires(
test_requires: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if test_requires is not None:
@@ -307,7 +310,7 @@ def test_audit_requires(
audit_requires: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if audit_requires is not None:
@@ -331,7 +334,7 @@ def test_test_extras(
test_extras: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if test_extras is not None:
@@ -354,7 +357,7 @@ def test_test_command(
test_command: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if test_command is not None:
@@ -377,7 +380,7 @@ def test_before_build(
before_build: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if before_build is not None:
@@ -399,7 +402,7 @@ def test_build_verbosity(
build_verbosity: int | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if build_verbosity is not None:
@@ -420,7 +423,7 @@ def test_build_verbosity(
def test_config_settings(
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
config_settings = (
@@ -507,7 +510,7 @@ def test_before_all(
before_all: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
) -> None:
if before_all is not None:
@@ -533,7 +536,7 @@ def test_dependency_versions(
dependency_versions: str | None,
platform_specific: bool,
platform: str,
intercepted_build_args: "ArgsInterceptor",
intercepted_build_args: ArgsInterceptor,
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
@@ -593,7 +596,7 @@ def test_debug_traceback(
@pytest.mark.parametrize("method", ["unset", "command_line", "env_var"])
def test_enable(
method: str, intercepted_build_args: "ArgsInterceptor", monkeypatch: pytest.MonkeyPatch
method: str, intercepted_build_args: ArgsInterceptor, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("CIBW_ENABLE", raising=False)
@@ -613,7 +616,7 @@ def test_enable(
def test_enable_all(
intercepted_build_args: "ArgsInterceptor", monkeypatch: pytest.MonkeyPatch
intercepted_build_args: ArgsInterceptor, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setattr(sys, "argv", [*sys.argv, "--enable", "all"])
monkeypatch.delenv("CIBW_ENABLE", raising=False)
@@ -625,7 +628,7 @@ def test_enable_all(
def test_enable_arg_inherits(
intercepted_build_args: "ArgsInterceptor", monkeypatch: pytest.MonkeyPatch
intercepted_build_args: ArgsInterceptor, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("CIBW_ENABLE", "pypy graalpy")
monkeypatch.setattr(sys, "argv", [*sys.argv, "--enable", "cpython-prerelease"])
@@ -652,7 +655,7 @@ def test_enable_arg_error_message(
assert "Valid group names are:" in err
def test_defaults(platform: str, intercepted_build_args: "ArgsInterceptor") -> None:
def test_defaults(platform: str, intercepted_build_args: ArgsInterceptor) -> None:
main()
build_options: BuildOptions = intercepted_build_args.args[0].build_options(identifier=None)
+8 -2
View File
@@ -1,3 +1,5 @@
from __future__ import annotations
import sys
import pytest
@@ -5,10 +7,14 @@ import pytest
from cibuildwheel.__main__ import main
from cibuildwheel.architecture import Architecture
from cibuildwheel.selector import EnableGroup
from cibuildwheel.typing import PlatformName
from ..conftest import MOCK_PACKAGE_DIR
from .conftest import ArgsInterceptor
TYPE_CHECKING = False
if TYPE_CHECKING:
from cibuildwheel.typing import PlatformName
from .conftest import ArgsInterceptor
@pytest.mark.parametrize("option_value", [None, "auto", ""])
@@ -1,13 +1,18 @@
from __future__ import annotations
import sys
import textwrap
from pathlib import Path
import pytest
from packaging.specifiers import SpecifierSet
from cibuildwheel.__main__ import main
from .conftest import ArgsInterceptor
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
from .conftest import ArgsInterceptor
@pytest.fixture(autouse=True)
+6 -1
View File
@@ -1,3 +1,5 @@
from __future__ import annotations
import contextlib
import json
import os
@@ -7,7 +9,6 @@ import subprocess
import sys
import textwrap
import time
from collections.abc import Iterator
from contextlib import nullcontext
from pathlib import Path, PurePath, PurePosixPath
@@ -25,6 +26,10 @@ from cibuildwheel.oci_container import (
_check_engine_version,
)
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Iterator
# Test utilities
# for these tests we use manylinux2014 images, because they're available on
+6 -1
View File
@@ -1,8 +1,9 @@
from __future__ import annotations
import os
import platform as platform_module
import textwrap
import unittest.mock
from collections.abc import Sequence
from pathlib import Path
from typing import Literal
@@ -25,6 +26,10 @@ from cibuildwheel.platforms import ALL_PLATFORM_MODULES, get_build_identifiers
from cibuildwheel.util import resources
from cibuildwheel.util.packaging import DependencyConstraints
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Sequence
PYPROJECT_1 = """
[tool.cibuildwheel]
build = ["cp38-*", "cp313-*"]
+8 -2
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import shlex
from pathlib import Path
from typing import Any, cast
import pytest
@@ -13,7 +14,12 @@ from cibuildwheel.options import (
ShlexTableFormat,
_resolve_cascade,
)
from cibuildwheel.typing import PlatformName
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
from cibuildwheel.typing import PlatformName
PYPROJECT_1 = """
[tool.cibuildwheel]
+6 -1
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import tomllib
from pathlib import Path
from textwrap import dedent
import pytest
@@ -10,6 +11,10 @@ from cibuildwheel.projectfiles import (
setup_py_python_requires,
)
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
def test_read_setup_py_simple(tmp_path: Path) -> None:
with open(tmp_path / "setup.py", "w") as f: