From 9e95e4fa66394bb1eb4d64271347eb1f8ffe1112 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 23 May 2026 11:34:06 +0200 Subject: [PATCH 1/3] chore: use `if TYPE_CHECKING:` blocks --- .pre-commit-config.yaml | 2 +- bin/inspect_all_known_projects.py | 7 ++- bin/projects.py | 7 ++- bin/update_pythons.py | 7 ++- cibuildwheel/__main__.py | 9 +++- cibuildwheel/architecture.py | 12 +++-- cibuildwheel/audit.py | 7 ++- cibuildwheel/bashlex_eval.py | 21 +++++---- cibuildwheel/environment.py | 10 ++++- cibuildwheel/extra.py | 11 ++++- cibuildwheel/frontend.py | 13 ++++-- cibuildwheel/logger.py | 14 +++--- cibuildwheel/oci_container.py | 18 +++++--- cibuildwheel/options.py | 11 ++++- cibuildwheel/platforms/__init__.py | 21 ++++++--- cibuildwheel/platforms/android.py | 13 ++++-- cibuildwheel/platforms/ios.py | 16 ++++--- cibuildwheel/platforms/linux.py | 9 ++-- cibuildwheel/platforms/macos.py | 19 +++++--- cibuildwheel/platforms/pyodide.py | 14 ++++-- cibuildwheel/platforms/windows.py | 14 ++++-- cibuildwheel/projectfiles.py | 9 +++- cibuildwheel/schema.py | 7 ++- cibuildwheel/selector.py | 10 ++++- cibuildwheel/util/cmd.py | 12 +++-- cibuildwheel/util/file.py | 7 ++- cibuildwheel/util/helpers.py | 11 +++-- cibuildwheel/util/packaging.py | 10 ++++- cibuildwheel/util/python_build_standalone.py | 7 ++- cibuildwheel/util/resources.py | 9 +++- cibuildwheel/venv.py | 10 ++++- pyproject.toml | 1 + test/conftest.py | 7 ++- test/test_0_basic.py | 7 ++- test/test_abi3audit.py | 7 ++- test/test_abi_variants.py | 11 +++-- test/test_before_all.py | 7 ++- test/test_before_build.py | 7 ++- test/test_before_test.py | 6 ++- test/test_build_frontend_args.py | 7 ++- test/test_build_skip.py | 7 ++- test/test_container_engine.py | 6 ++- test/test_container_images.py | 7 ++- test/test_cpp_standards.py | 6 ++- test/test_custom_repair_wheel.py | 7 ++- test/test_dependency_versions.py | 7 ++- test/test_emulation.py | 7 ++- test/test_environment.py | 7 ++- test/test_from_sdist.py | 13 ++++-- test/test_ios.py | 7 ++- test/test_linux_python.py | 7 ++- test/test_macos_archs.py | 7 ++- test/test_manylinuxXXXX_only.py | 7 ++- test/test_meson_python.py | 6 ++- test/test_musllinux_X_Y_only.py | 7 ++- test/test_pep518.py | 6 +++ test/test_projects/base.py | 7 ++- test/test_pure_wheel.py | 6 +++ test/test_pyodide.py | 7 ++- test/test_ssl.py | 7 ++- test/test_subdir_package.py | 7 ++- test/test_testing.py | 7 ++- test/test_troubleshooting.py | 7 ++- test/test_wheel_tag.py | 6 ++- test/utils.py | 7 ++- unit_test/architecture_test.py | 7 ++- unit_test/audit_test.py | 7 ++- unit_test/download_test.py | 7 ++- unit_test/get_platform_test.py | 7 ++- unit_test/linux_build_steps_test.py | 11 +++-- unit_test/main_commands_test.py | 7 ++- unit_test/main_tests/conftest.py | 7 ++- unit_test/main_tests/main_options_test.py | 45 ++++++++++--------- unit_test/main_tests/main_platform_test.py | 10 ++++- .../main_tests/main_requires_python_test.py | 9 +++- unit_test/oci_container_test.py | 7 ++- unit_test/options_test.py | 7 ++- unit_test/options_toml_test.py | 10 ++++- unit_test/projectfiles_test.py | 7 ++- 79 files changed, 564 insertions(+), 166 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4188fd65f..a1cb316db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: exclude: ^cibuildwheel/resources/android/android.patch$ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 6fec9b7edb08fd9989088709d864a7826dc74e80 # frozen: v0.15.12 + rev: 0c7b6c989466a93942def1f84baf36ddfcd60c83 # frozen: v0.15.14 hooks: - id: ruff-check args: ["--fix"] diff --git a/bin/inspect_all_known_projects.py b/bin/inspect_all_known_projects.py index 039647962..f328c09f0 100755 --- a/bin/inspect_all_known_projects.py +++ b/bin/inspect_all_known_projects.py @@ -24,8 +24,9 @@ the results without the `--online` setting. """ +from __future__ import annotations + import ast -from collections.abc import Iterable, Iterator from pathlib import Path import click @@ -35,6 +36,10 @@ from cibuildwheel.projectfiles import Analyzer +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Iterable, Iterator + DIR = Path(__file__).parent.resolve() diff --git a/bin/projects.py b/bin/projects.py index f58d1bdc9..1b586d29e 100755 --- a/bin/projects.py +++ b/bin/projects.py @@ -17,13 +17,14 @@ git diff """ +from __future__ import annotations + import builtins import functools import textwrap import urllib.error import urllib.request import xml.dom.minidom -from collections.abc import Iterable, Mapping, Sequence from datetime import UTC, datetime from io import StringIO from pathlib import Path @@ -33,6 +34,10 @@ import yaml from github import Auth, Github, GithubException +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Iterable, Mapping, Sequence + ICONS = ( "github", "azurepipelines", diff --git a/bin/update_pythons.py b/bin/update_pythons.py index b99a079ef..5a8099196 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -12,14 +12,13 @@ # [tool.uv.sources] # cibuildwheel = { path = ".." } # /// - +from __future__ import annotations import difflib import logging import operator import re import tomllib -from collections.abc import Mapping, MutableMapping from pathlib import Path from typing import Any, Final, Literal, TypedDict from xml.etree import ElementTree as ET @@ -35,6 +34,10 @@ from cibuildwheel.extra import dump_python_configurations, get_pyodide_xbuildenv_info from cibuildwheel.platforms.android import android_triplet +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Mapping, MutableMapping + log = logging.getLogger("cibw") # Looking up the dir instead of using utils.resources_dir diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index e0def5488..c25d8bc56 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import argparse import contextlib import dataclasses @@ -8,10 +10,8 @@ import textwrap import traceback import typing -from collections.abc import Generator, Iterable, Sequence from pathlib import Path from tempfile import mkdtemp -from typing import Any, Literal, TextIO import cibuildwheel from cibuildwheel import errors @@ -27,6 +27,11 @@ from cibuildwheel.util.helpers import strtobool from cibuildwheel.util.resources import read_all_configs +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Generator, Iterable, Sequence + from typing import Any, Literal, TextIO + @dataclasses.dataclass class GlobalOptions: diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 655b17623..41d5ad863 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -1,15 +1,21 @@ +from __future__ import annotations + import platform as platform_module import re import shutil import subprocess import sys import typing -from collections.abc import Set from enum import StrEnum, auto -from typing import Final, Literal, Self from cibuildwheel import errors -from cibuildwheel.typing import PlatformName + +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Set + from typing import Final, Literal, Self + + from cibuildwheel.typing import PlatformName PRETTY_NAMES: Final[dict[PlatformName, str]] = { "linux": "Linux", diff --git a/cibuildwheel/audit.py b/cibuildwheel/audit.py index f91b01558..10f4c7cf1 100644 --- a/cibuildwheel/audit.py +++ b/cibuildwheel/audit.py @@ -1,15 +1,20 @@ +from __future__ import annotations + import subprocess import sys from pathlib import Path from cibuildwheel import errors from cibuildwheel.logger import log -from cibuildwheel.options import BuildOptions from cibuildwheel.util.cmd import call, shell from cibuildwheel.util.helpers import prepare_command from cibuildwheel.util.packaging import is_abi3_wheel from cibuildwheel.venv import activate_virtualenv, find_uv, virtualenv +TYPE_CHECKING = False +if TYPE_CHECKING: + from cibuildwheel.options import BuildOptions + def run_audit( *, diff --git a/cibuildwheel/bashlex_eval.py b/cibuildwheel/bashlex_eval.py index 3d1ac1185..85cdcb1ad 100644 --- a/cibuildwheel/bashlex_eval.py +++ b/cibuildwheel/bashlex_eval.py @@ -1,16 +1,21 @@ +from __future__ import annotations + import dataclasses import subprocess -from collections.abc import ( - Callable, - Iterable, - Mapping, - Sequence, -) import bashlex -# a function that takes a command and the environment, and returns the result -EnvironmentExecutor = Callable[[list[str], dict[str, str]], str] +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import ( + Callable, + Iterable, + Mapping, + Sequence, + ) + + # a function that takes a command and the environment, and returns the result + EnvironmentExecutor = Callable[[list[str], dict[str, str]], str] def local_environment_executor(command: Sequence[str], env: Mapping[str, str]) -> str: diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index c9e534127..bc5d13bf0 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -1,12 +1,18 @@ +from __future__ import annotations + import dataclasses -from collections.abc import Mapping, Sequence -from typing import Any, Protocol +from typing import Protocol import bashlex import bashlex.errors from cibuildwheel import bashlex_eval +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Mapping, Sequence + from typing import Any + class EnvironmentParseError(Exception): pass diff --git a/cibuildwheel/extra.py b/cibuildwheel/extra.py index d075d3217..d07e7784b 100644 --- a/cibuildwheel/extra.py +++ b/cibuildwheel/extra.py @@ -2,17 +2,24 @@ These are utilities for the `/bin` scripts, not for the `cibuildwheel` program. """ +from __future__ import annotations + import json import time import typing import urllib.error import urllib.request -from collections.abc import Mapping, Sequence from io import StringIO -from typing import Any, NotRequired, Protocol +from typing import NotRequired, Protocol from cibuildwheel import __version__ as cibw_version +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Mapping, Sequence + from typing import Any + + __all__ = ("Printable", "dump_python_configurations") diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index 11c3e93d4..463570346 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -1,12 +1,19 @@ +from __future__ import annotations + import dataclasses import shlex import typing -from collections.abc import Sequence -from typing import Literal, Self, get_args +from typing import Literal, get_args -from cibuildwheel.typing import PathOrStr from cibuildwheel.util.helpers import parse_key_value_string, prepare_command +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Sequence + from typing import Self + + from cibuildwheel.typing import PathOrStr + BuildFrontendName = Literal["pip", "build", "build[uv]", "uv"] diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index b6f8b8029..da33370e8 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import codecs import contextlib import dataclasses @@ -9,9 +11,7 @@ import sys import textwrap import time -from collections.abc import Generator from pathlib import Path -from typing import IO, AnyStr, Final, Literal import humanize @@ -19,9 +19,13 @@ TYPE_CHECKING = False if TYPE_CHECKING: + from collections.abc import Generator + from typing import IO, AnyStr, Final, Literal + from cibuildwheel.options import Options -FoldPattern = tuple[str, str] + FoldPattern = tuple[str, str] + DEFAULT_FOLD_PATTERN: Final[FoldPattern] = ("{name}", "") FOLD_PATTERNS: Final[dict[str, FoldPattern]] = { "azure": ("##[group]{name}", "##[endgroup]"), @@ -235,7 +239,7 @@ def error(self, error: BaseException | str) -> None: print(f"cibuildwheel: {c.bright_red}error{c.end}: {error}\n", file=sys.stderr) @contextlib.contextmanager - def print_summary(self, *, options: "Options") -> Generator[None, None, None]: + def print_summary(self, *, options: Options) -> Generator[None, None, None]: start = time.time() yield duration = time.time() - start @@ -293,7 +297,7 @@ def _fold_group_identifier(name: str) -> str: # lowercase, shorten return identifier.lower()[:20] - def _github_step_summary(self, duration: float, options: "Options") -> str: + def _github_step_summary(self, duration: float, options: Options) -> str: """ Returns the GitHub step summary, in markdown format. """ diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index 88144469c..a95ed5215 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import io import json @@ -10,19 +12,25 @@ import textwrap import typing import uuid -from collections.abc import Mapping, Sequence from enum import Enum -from pathlib import Path, PurePath, PurePosixPath -from types import TracebackType -from typing import IO, Literal, Self, assert_never +from pathlib import PurePosixPath +from typing import Literal, assert_never from cibuildwheel.ci import CIProvider, detect_ci_provider from cibuildwheel.errors import OCIEngineTooOldError from cibuildwheel.logger import log -from cibuildwheel.typing import PathOrStr from cibuildwheel.util.cmd import call from cibuildwheel.util.helpers import FlexibleVersion, parse_key_value_string, strtobool +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Mapping, Sequence + from pathlib import Path, PurePath + from types import TracebackType + from typing import IO, Self + + from cibuildwheel.typing import PathOrStr + ContainerEngineName = Literal["docker", "podman"] diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index 800c882fa..89b646812 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import collections import configparser import contextlib @@ -8,9 +10,9 @@ import shlex import textwrap import tomllib -from collections.abc import Callable, Generator, Iterable, Mapping, Sequence, Set +from collections.abc import Mapping, Sequence from pathlib import Path -from typing import Any, Final, Literal, Self, assert_never +from typing import assert_never from packaging.specifiers import SpecifierSet @@ -27,6 +29,11 @@ from cibuildwheel.util.helpers import format_safe, parse_key_value_string, strtobool, unwrap from cibuildwheel.util.packaging import DependencyConstraints +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Callable, Generator, Iterable, Set + from typing import Any, Final, Literal, Self + MANYLINUX_ARCHS: Final[tuple[str, ...]] = ( "x86_64", "i686", diff --git a/cibuildwheel/platforms/__init__.py b/cibuildwheel/platforms/__init__.py index 8549a4039..cfe22cbba 100644 --- a/cibuildwheel/platforms/__init__.py +++ b/cibuildwheel/platforms/__init__.py @@ -1,14 +1,21 @@ +from __future__ import annotations + import sys -from collections.abc import Sequence -from pathlib import Path -from typing import Final, Protocol +from typing import Protocol from cibuildwheel import errors -from cibuildwheel.architecture import Architecture -from cibuildwheel.options import Options from cibuildwheel.platforms import android, ios, linux, macos, pyodide, windows -from cibuildwheel.selector import BuildSelector -from cibuildwheel.typing import GenericPythonConfiguration, PlatformName + +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Sequence + from pathlib import Path + from typing import Final + + from cibuildwheel.architecture import Architecture + from cibuildwheel.options import Options + from cibuildwheel.selector import BuildSelector + from cibuildwheel.typing import GenericPythonConfiguration, PlatformName class PlatformModule(Protocol): diff --git a/cibuildwheel/platforms/android.py b/cibuildwheel/platforms/android.py index ae2b2a79f..b8bd4bf56 100644 --- a/cibuildwheel/platforms/android.py +++ b/cibuildwheel/platforms/android.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import csv import hashlib import os @@ -7,7 +9,6 @@ import shutil import subprocess import sysconfig -from collections.abc import Iterable, Iterator, MutableMapping from dataclasses import dataclass from os.path import relpath from pathlib import Path @@ -31,8 +32,6 @@ prepare_config_settings, ) from cibuildwheel.logger import log -from cibuildwheel.options import BuildOptions, Options -from cibuildwheel.selector import BuildSelector from cibuildwheel.util import resources from cibuildwheel.util.cmd import call, shell from cibuildwheel.util.file import CIBW_CACHE_PATH, copy_test_sources, download, move_file @@ -41,8 +40,14 @@ from cibuildwheel.util.python_build_standalone import create_python_build_standalone_environment from cibuildwheel.venv import constraint_flags, find_uv, virtualenv -RESOURCES_ANDROID = resources.PATH / "android" +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Iterable, Iterator, MutableMapping + from cibuildwheel.options import BuildOptions, Options + from cibuildwheel.selector import BuildSelector + +RESOURCES_ANDROID = resources.PATH / "android" ANDROID_TRIPLET = { "arm64_v8a": "aarch64-linux-android", "x86_64": "x86_64-linux-android", diff --git a/cibuildwheel/platforms/ios.py b/cibuildwheel/platforms/ios.py index 40c66b877..225662e15 100644 --- a/cibuildwheel/platforms/ios.py +++ b/cibuildwheel/platforms/ios.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import os import platform @@ -6,25 +8,20 @@ import subprocess import sys import textwrap -from collections.abc import Sequence, Set from pathlib import Path from typing import assert_never from filelock import FileLock from cibuildwheel import errors -from cibuildwheel.architecture import Architecture from cibuildwheel.audit import run_audit -from cibuildwheel.environment import ParsedEnvironment from cibuildwheel.frontend import ( BuildFrontendName, get_build_frontend_extra_flags, prepare_config_settings, ) from cibuildwheel.logger import log -from cibuildwheel.options import Options from cibuildwheel.platforms.macos import install_cpython as install_build_cpython -from cibuildwheel.selector import BuildSelector from cibuildwheel.util import resources from cibuildwheel.util.cmd import call, shell, split_command from cibuildwheel.util.file import CIBW_CACHE_PATH, copy_test_sources, download, move_file @@ -32,6 +29,15 @@ from cibuildwheel.util.packaging import find_compatible_wheel from cibuildwheel.venv import constraint_flags, virtualenv +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Sequence, Set + + from cibuildwheel.architecture import Architecture + from cibuildwheel.environment import ParsedEnvironment + from cibuildwheel.options import Options + from cibuildwheel.selector import BuildSelector + @dataclasses.dataclass(frozen=True, kw_only=True) class PythonConfiguration: diff --git a/cibuildwheel/platforms/linux.py b/cibuildwheel/platforms/linux.py index a9f3e1fad..9b4559bac 100644 --- a/cibuildwheel/platforms/linux.py +++ b/cibuildwheel/platforms/linux.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import contextlib import dataclasses import shutil @@ -5,7 +7,6 @@ import sys import textwrap from collections import OrderedDict -from collections.abc import Iterable, Iterator, Sequence, Set from pathlib import Path, PurePath, PurePosixPath from typing import assert_never @@ -15,8 +16,6 @@ from cibuildwheel.frontend import get_build_frontend_extra_flags, prepare_config_settings from cibuildwheel.logger import log from cibuildwheel.oci_container import OCIContainer, OCIContainerEngineConfig, OCIPlatform -from cibuildwheel.options import BuildOptions, Options -from cibuildwheel.selector import BuildSelector from cibuildwheel.util import resources from cibuildwheel.util.file import copy_test_sources from cibuildwheel.util.helpers import prepare_command, unwrap @@ -24,6 +23,10 @@ TYPE_CHECKING = False if TYPE_CHECKING: + from collections.abc import Iterable, Iterator, Sequence, Set + + from cibuildwheel.options import BuildOptions, Options + from cibuildwheel.selector import BuildSelector from cibuildwheel.typing import PathOrStr ARCHITECTURE_OCI_PLATFORM_MAP = { diff --git a/cibuildwheel/platforms/macos.py b/cibuildwheel/platforms/macos.py index bb830a346..3208bcd1a 100644 --- a/cibuildwheel/platforms/macos.py +++ b/cibuildwheel/platforms/macos.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import functools import inspect @@ -8,26 +10,21 @@ import subprocess import sys import typing -from collections.abc import Set from pathlib import Path -from typing import Literal, assert_never +from typing import assert_never from filelock import FileLock from packaging.version import Version from cibuildwheel import errors -from cibuildwheel.architecture import Architecture from cibuildwheel.audit import run_audit from cibuildwheel.ci import detect_ci_provider -from cibuildwheel.environment import ParsedEnvironment from cibuildwheel.frontend import ( BuildFrontendName, get_build_frontend_extra_flags, prepare_config_settings, ) from cibuildwheel.logger import log -from cibuildwheel.options import Options -from cibuildwheel.selector import BuildSelector from cibuildwheel.util import resources from cibuildwheel.util.cmd import call, shell from cibuildwheel.util.file import CIBW_CACHE_PATH, copy_test_sources, download, move_file @@ -35,6 +32,16 @@ from cibuildwheel.util.packaging import find_compatible_wheel, get_pip_version from cibuildwheel.venv import constraint_flags, find_uv, target_marker_env, virtualenv +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Set + from typing import Literal + + from cibuildwheel.architecture import Architecture + from cibuildwheel.environment import ParsedEnvironment + from cibuildwheel.options import Options + from cibuildwheel.selector import BuildSelector + @functools.cache def get_macos_version() -> tuple[int, int]: diff --git a/cibuildwheel/platforms/pyodide.py b/cibuildwheel/platforms/pyodide.py index 262eac2b8..53c66d9f8 100644 --- a/cibuildwheel/platforms/pyodide.py +++ b/cibuildwheel/platforms/pyodide.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import functools import json @@ -7,7 +9,6 @@ import sys import tomllib import typing -from collections.abc import Set from pathlib import Path from tempfile import TemporaryDirectory from typing import Final, TypedDict @@ -17,11 +18,8 @@ from cibuildwheel import errors from cibuildwheel.architecture import Architecture from cibuildwheel.audit import run_audit -from cibuildwheel.environment import ParsedEnvironment from cibuildwheel.frontend import get_build_frontend_extra_flags, prepare_config_settings from cibuildwheel.logger import log -from cibuildwheel.options import Options -from cibuildwheel.selector import BuildSelector from cibuildwheel.util import resources from cibuildwheel.util.cmd import call, shell from cibuildwheel.util.file import ( @@ -40,6 +38,14 @@ ) from cibuildwheel.venv import constraint_flags, virtualenv +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Set + + from cibuildwheel.environment import ParsedEnvironment + from cibuildwheel.options import Options + from cibuildwheel.selector import BuildSelector + IS_WIN: Final[bool] = sys.platform.startswith("win") diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index 1a858c8fb..8b30c710c 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import dataclasses import json import os @@ -5,7 +7,6 @@ import shutil import subprocess import textwrap -from collections.abc import MutableMapping, Sequence, Set from functools import cache from pathlib import Path from typing import assert_never @@ -15,15 +16,12 @@ from cibuildwheel import errors from cibuildwheel.architecture import Architecture from cibuildwheel.audit import run_audit -from cibuildwheel.environment import ParsedEnvironment from cibuildwheel.frontend import ( BuildFrontendName, get_build_frontend_extra_flags, prepare_config_settings, ) from cibuildwheel.logger import log -from cibuildwheel.options import Options -from cibuildwheel.selector import BuildSelector from cibuildwheel.util import resources from cibuildwheel.util.cmd import call, shell from cibuildwheel.util.file import ( @@ -37,6 +35,14 @@ from cibuildwheel.util.packaging import find_compatible_wheel, get_pip_version from cibuildwheel.venv import constraint_flags, find_uv, target_marker_env, virtualenv +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import MutableMapping, Sequence, Set + + from cibuildwheel.environment import ParsedEnvironment + from cibuildwheel.options import Options + from cibuildwheel.selector import BuildSelector + def get_nuget_args( version: str, arch: str, free_threaded: bool, output_directory: Path diff --git a/cibuildwheel/projectfiles.py b/cibuildwheel/projectfiles.py index 3117486fe..41af8b1f7 100644 --- a/cibuildwheel/projectfiles.py +++ b/cibuildwheel/projectfiles.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import ast import configparser import contextlib -from pathlib import Path -from typing import Any import dependency_groups +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + from typing import Any + def get_parent(node: ast.AST | None, depth: int = 1) -> ast.AST | None: for _ in range(depth): diff --git a/cibuildwheel/schema.py b/cibuildwheel/schema.py index ec070278b..dde0efcc1 100644 --- a/cibuildwheel/schema.py +++ b/cibuildwheel/schema.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import json -from typing import Any from cibuildwheel.util import resources +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Any + def get_schema(tool_name: str = "cibuildwheel") -> dict[str, Any]: "Get the stored complete schema for cibuildwheel settings." diff --git a/cibuildwheel/selector.py b/cibuildwheel/selector.py index 5f3853a08..e9fa8c130 100644 --- a/cibuildwheel/selector.py +++ b/cibuildwheel/selector.py @@ -1,13 +1,19 @@ +from __future__ import annotations + import dataclasses import itertools from enum import StrEnum from fnmatch import fnmatch -from typing import Self import bracex -from packaging.specifiers import SpecifierSet from packaging.version import Version +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Self + + from packaging.specifiers import SpecifierSet + def selector_matches(patterns: str, string: str) -> bool: """ diff --git a/cibuildwheel/util/cmd.py b/cibuildwheel/util/cmd.py index aba6cf179..ed864c275 100644 --- a/cibuildwheel/util/cmd.py +++ b/cibuildwheel/util/cmd.py @@ -1,14 +1,20 @@ +from __future__ import annotations + import os import shlex import shutil import subprocess import sys import typing -from collections.abc import Iterator, Mapping -from typing import Final, Literal from cibuildwheel.errors import FatalError -from cibuildwheel.typing import PathOrStr + +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Iterator, Mapping + from typing import Final, Literal + + from cibuildwheel.typing import PathOrStr _IS_WIN: Final[bool] = sys.platform.startswith("win") diff --git a/cibuildwheel/util/file.py b/cibuildwheel/util/file.py index 04e40f3d6..eaec26486 100644 --- a/cibuildwheel/util/file.py +++ b/cibuildwheel/util/file.py @@ -1,10 +1,11 @@ +from __future__ import annotations + import os import shutil import ssl import tarfile import time import urllib.request -from collections.abc import Callable from pathlib import Path, PurePath from typing import Final from zipfile import ZipFile @@ -14,6 +15,10 @@ from cibuildwheel.errors import FatalError +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Callable + DEFAULT_CIBW_CACHE_PATH: Final[Path] = user_cache_path(appname="cibuildwheel", appauthor="pypa") CIBW_CACHE_PATH: Final[Path] = Path( os.environ.get("CIBW_CACHE_PATH", DEFAULT_CIBW_CACHE_PATH) diff --git a/cibuildwheel/util/helpers.py b/cibuildwheel/util/helpers.py index 6e17cb2eb..6eb79a959 100644 --- a/cibuildwheel/util/helpers.py +++ b/cibuildwheel/util/helpers.py @@ -1,13 +1,18 @@ +from __future__ import annotations + import dataclasses import itertools -import os import re import shlex import textwrap from collections import defaultdict -from collections.abc import Sequence -from cibuildwheel.typing import PathOrStr +TYPE_CHECKING = False +if TYPE_CHECKING: + import os + from collections.abc import Sequence + + from cibuildwheel.typing import PathOrStr def format_safe(template: str, **kwargs: str | os.PathLike[str]) -> str: diff --git a/cibuildwheel/util/packaging.py b/cibuildwheel/util/packaging.py index 1dc71eaf0..d8bb57c66 100644 --- a/cibuildwheel/util/packaging.py +++ b/cibuildwheel/util/packaging.py @@ -1,8 +1,9 @@ +from __future__ import annotations + import shlex -from collections.abc import Mapping, Sequence from dataclasses import dataclass, field from pathlib import Path, PurePath -from typing import Literal, Self, TypeVar +from typing import TypeVar from packaging.utils import parse_wheel_filename @@ -10,6 +11,11 @@ from cibuildwheel.util.cmd import call from cibuildwheel.util.helpers import parse_key_value_string, unwrap +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Mapping, Sequence + from typing import Literal, Self + @dataclass(kw_only=True) class DependencyConstraints: diff --git a/cibuildwheel/util/python_build_standalone.py b/cibuildwheel/util/python_build_standalone.py index f8dca73ce..f6f9897e0 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -1,15 +1,20 @@ +from __future__ import annotations + import fnmatch import functools import json import platform import typing -from pathlib import Path from filelock import FileLock from cibuildwheel.util.file import download, extract_tar from cibuildwheel.util.resources import PYTHON_BUILD_STANDALONE_RELEASES +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + class PythonBuildStandaloneAsset(typing.TypedDict): name: str diff --git a/cibuildwheel/util/resources.py b/cibuildwheel/util/resources.py index 37775b188..0ac9e8f98 100644 --- a/cibuildwheel/util/resources.py +++ b/cibuildwheel/util/resources.py @@ -1,9 +1,14 @@ +from __future__ import annotations + import functools import tomllib from pathlib import Path -from typing import Final -from cibuildwheel.typing import PlatformName +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Final + + from cibuildwheel.typing import PlatformName PATH: Final[Path] = Path(__file__).parent.parent / "resources" INSTALL_CERTIFI_SCRIPT: Final[Path] = PATH / "install_certifi.py" diff --git a/cibuildwheel/venv.py b/cibuildwheel/venv.py index f38ab11ec..91c21f069 100644 --- a/cibuildwheel/venv.py +++ b/cibuildwheel/venv.py @@ -1,12 +1,13 @@ +from __future__ import annotations + import contextlib import functools import os import shutil import sys import tomllib -from collections.abc import Sequence from pathlib import Path -from typing import Final, cast +from typing import cast from filelock import FileLock from packaging.markers import default_environment @@ -17,6 +18,11 @@ from cibuildwheel.util.cmd import call from cibuildwheel.util.file import CIBW_CACHE_PATH, download +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Sequence + from typing import Final + _IS_WIN: Final[bool] = sys.platform.startswith("win") diff --git a/pyproject.toml b/pyproject.toml index fd84620b5..e10a6b55a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -224,6 +224,7 @@ flake8-unused-arguments.ignore-variadic-names = true flake8-tidy-imports.ban-relative-imports = "all" flake8-annotations.allow-star-arg-any = true flake8-annotations.mypy-init-return = true +future-annotations = true [tool.ruff.lint.flake8-tidy-imports.banned-api] "typing.Mapping".msg = "Use collections.abc.Mapping instead." diff --git a/test/conftest.py b/test/conftest.py index 8949dc80d..15d2f57f2 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,7 +1,8 @@ +from __future__ import annotations + import json import os import subprocess -from collections.abc import Generator import pytest from filelock import FileLock @@ -16,6 +17,10 @@ from . import utils from .utils import DEFAULT_CIBW_ENABLE, EMULATED_ARCHS, get_platform +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Generator + def pytest_addoption(parser: pytest.Parser) -> None: parser.addoption( diff --git a/test/test_0_basic.py b/test/test_0_basic.py index ec9b6f166..8c1d9b75d 100644 --- a/test/test_0_basic.py +++ b/test/test_0_basic.py @@ -1,5 +1,6 @@ +from __future__ import annotations + import textwrap -from pathlib import Path import packaging.utils import pytest @@ -9,6 +10,10 @@ from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + basic_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( """ diff --git a/test/test_abi3audit.py b/test/test_abi3audit.py index adacf25c5..1a38fc32d 100644 --- a/test/test_abi3audit.py +++ b/test/test_abi3audit.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import subprocess import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + pyproject_toml = r""" [build-system] requires = ["setuptools", "wheel"] diff --git a/test/test_abi_variants.py b/test/test_abi_variants.py index bf0907a35..b89f8c763 100644 --- a/test/test_abi_variants.py +++ b/test/test_abi_variants.py @@ -1,10 +1,15 @@ -import textwrap -from pathlib import Path +from __future__ import annotations -import pytest +import textwrap from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + + import pytest + pyproject_toml = r""" [build-system] requires = ["setuptools", "wheel"] diff --git a/test/test_before_all.py b/test/test_before_all.py index 156b38507..2f36f38f5 100644 --- a/test/test_before_all.py +++ b/test/test_before_all.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import subprocess import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_before_build_asserts = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_before_build.py b/test/test_before_build.py index 37cbe9ace..6986591c3 100644 --- a/test/test_before_build.py +++ b/test/test_before_build.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import subprocess import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + # pyodide does not support building without isolation, need to check the base_prefix SYS_PREFIX = f"sys.{'base_' if utils.get_platform() == 'pyodide' else ''}prefix" diff --git a/test/test_before_test.py b/test/test_before_test.py index d067edd7a..ee0cef734 100644 --- a/test/test_before_test.py +++ b/test/test_before_test.py @@ -1,7 +1,11 @@ -from pathlib import Path +from __future__ import annotations from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + before_test_project = test_projects.new_c_project() before_test_project.files["test/spam_test.py"] = r""" import sys diff --git a/test/test_build_frontend_args.py b/test/test_build_frontend_args.py index 4940e02fc..3c1aa6a2c 100644 --- a/test/test_build_frontend_args.py +++ b/test/test_build_frontend_args.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import subprocess -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + @pytest.mark.parametrize( "frontend_name", diff --git a/test/test_build_skip.py b/test/test_build_skip.py index d9b1bf32d..f6dfcaae0 100644 --- a/test/test_build_skip.py +++ b/test/test_build_skip.py @@ -1,8 +1,13 @@ +from __future__ import annotations + import textwrap -from pathlib import Path from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_skip_asserts = test_projects.new_c_project( setup_py_add=textwrap.dedent( rf""" diff --git a/test/test_container_engine.py b/test/test_container_engine.py index 68968dfdc..34f6a151e 100644 --- a/test/test_container_engine.py +++ b/test/test_container_engine.py @@ -1,9 +1,13 @@ -from pathlib import Path +from __future__ import annotations import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + basic_project = test_projects.new_c_project() diff --git a/test/test_container_images.py b/test/test_container_images.py index fa8bc5181..5c044cdcb 100644 --- a/test/test_container_images.py +++ b/test/test_container_images.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import platform import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + dockcross_only_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_cpp_standards.py b/test/test_cpp_standards.py index deba8e645..07bb5ddde 100644 --- a/test/test_cpp_standards.py +++ b/test/test_cpp_standards.py @@ -1,10 +1,14 @@ -from pathlib import Path +from __future__ import annotations import jinja2 from . import utils from .test_projects import TestProject +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + cpp_test_project = TestProject() setup_py_template = r""" diff --git a/test/test_custom_repair_wheel.py b/test/test_custom_repair_wheel.py index 8bfe6a3fa..5f5f9a493 100644 --- a/test/test_custom_repair_wheel.py +++ b/test/test_custom_repair_wheel.py @@ -1,7 +1,8 @@ +from __future__ import annotations + import subprocess import textwrap from contextlib import nullcontext as does_not_raise -from pathlib import Path import pytest @@ -9,6 +10,10 @@ from . import utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + basic_project = test_projects.new_c_project() basic_project.files["repair.py"] = """ import shutil diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index 974624018..714ecf90a 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -1,8 +1,9 @@ +from __future__ import annotations + import json import re import subprocess import textwrap -from pathlib import Path import pytest @@ -10,6 +11,10 @@ from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + VERSION_REGEX = r"([\w-]+)==([^;\s]+)" CHECK_VERSIONS_SCRIPT = """\ diff --git a/test/test_emulation.py b/test/test_emulation.py index b475b6a73..3c6aa6d6b 100644 --- a/test/test_emulation.py +++ b/test/test_emulation.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import itertools import subprocess -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_a_test = test_projects.new_c_project() project_with_a_test.files["test/spam_test.py"] = r""" diff --git a/test/test_environment.py b/test/test_environment.py index b12a89999..aa56bb44d 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -1,13 +1,18 @@ +from __future__ import annotations + import os import subprocess import sys import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_environment_asserts = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_from_sdist.py b/test/test_from_sdist.py index 094e96d8c..775b81bcd 100644 --- a/test/test_from_sdist.py +++ b/test/test_from_sdist.py @@ -1,16 +1,21 @@ +from __future__ import annotations + import os import subprocess import sys import textwrap -from collections.abc import Mapping from pathlib import Path from tempfile import TemporaryDirectory -import pytest +from . import test_projects, utils + +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Mapping -from test.test_projects.base import TestProject + import pytest -from . import test_projects, utils + from test.test_projects.base import TestProject # utilities diff --git a/test/test_ios.py b/test/test_ios.py index b0739d587..d36437d91 100644 --- a/test/test_ios.py +++ b/test/test_ios.py @@ -1,14 +1,19 @@ +from __future__ import annotations + import os import platform import shutil import subprocess import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + pytestmark = pytest.mark.ios CIBW_PLATFORM = os.environ.get("CIBW_PLATFORM", "ios") diff --git a/test/test_linux_python.py b/test/test_linux_python.py index d0f93f55d..0fa33967e 100644 --- a/test/test_linux_python.py +++ b/test/test_linux_python.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import platform import subprocess -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + def test_python_exist(tmp_path: Path, capfd: pytest.CaptureFixture[str]) -> None: if utils.get_platform() != "linux": diff --git a/test/test_macos_archs.py b/test/test_macos_archs.py index b5274bc69..6cbecb130 100644 --- a/test/test_macos_archs.py +++ b/test/test_macos_archs.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import platform -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + basic_project = test_projects.new_c_project() basic_project.files["tests/test_suite.py"] = r""" import platform diff --git a/test/test_manylinuxXXXX_only.py b/test/test_manylinuxXXXX_only.py index 2fbb4e3f5..135e33eee 100644 --- a/test/test_manylinuxXXXX_only.py +++ b/test/test_manylinuxXXXX_only.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import platform import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + # TODO: specify these at runtime according to manylinux_image project_with_manylinux_symbols = test_projects.new_c_project( spam_c_top_level_add=textwrap.dedent( diff --git a/test/test_meson_python.py b/test/test_meson_python.py index 5d507be69..7c49b615b 100644 --- a/test/test_meson_python.py +++ b/test/test_meson_python.py @@ -1,9 +1,13 @@ -from pathlib import Path +from __future__ import annotations import packaging.utils from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + meson_project = test_projects.new_meson_project() diff --git a/test/test_musllinux_X_Y_only.py b/test/test_musllinux_X_Y_only.py index 2a3f70af2..b9dde2565 100644 --- a/test/test_musllinux_X_Y_only.py +++ b/test/test_musllinux_X_Y_only.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_manylinux_symbols = test_projects.new_c_project( spam_c_top_level_add=textwrap.dedent( r""" diff --git a/test/test_pep518.py b/test/test_pep518.py index 4bc1fa6bf..4bd74b2db 100644 --- a/test/test_pep518.py +++ b/test/test_pep518.py @@ -1,8 +1,14 @@ +from __future__ import annotations + import textwrap from pathlib import Path from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + basic_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( """ diff --git a/test/test_projects/base.py b/test/test_projects/base.py index dd8f2ce21..c168345e9 100644 --- a/test/test_projects/base.py +++ b/test/test_projects/base.py @@ -1,8 +1,13 @@ -from pathlib import Path +from __future__ import annotations + from typing import Any, Self import jinja2 +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + FilesDict = dict[str, str | jinja2.Template] TemplateContext = dict[str, Any] diff --git a/test/test_pure_wheel.py b/test/test_pure_wheel.py index dc7c0995d..300e44f05 100644 --- a/test/test_pure_wheel.py +++ b/test/test_pure_wheel.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import subprocess from pathlib import Path @@ -7,6 +9,10 @@ from . import utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + pure_python_project = test_projects.TestProject() pure_python_project.files["setup.py"] = """ from setuptools import Extension, setup diff --git a/test/test_pyodide.py b/test/test_pyodide.py index 96873661d..008adb1ec 100644 --- a/test/test_pyodide.py +++ b/test/test_pyodide.py @@ -1,9 +1,10 @@ +from __future__ import annotations + import contextlib import os import subprocess import sys import textwrap -from pathlib import Path import pytest @@ -11,6 +12,10 @@ from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + pytestmark = pytest.mark.pyodide CIBW_PLATFORM = os.environ.get("CIBW_PLATFORM", "pyodide") diff --git a/test/test_ssl.py b/test/test_ssl.py index c43d18fbe..b8e8b3f33 100644 --- a/test/test_ssl.py +++ b/test/test_ssl.py @@ -1,10 +1,15 @@ +from __future__ import annotations + import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_ssl_tests = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_subdir_package.py b/test/test_subdir_package.py index e842b2d52..83cec17f1 100644 --- a/test/test_subdir_package.py +++ b/test/test_subdir_package.py @@ -1,12 +1,17 @@ +from __future__ import annotations + from pathlib import Path import jinja2 -import pytest from . import utils from .test_projects import TestProject from .test_projects.c import SPAM_C_TEMPLATE +TYPE_CHECKING = False +if TYPE_CHECKING: + import pytest + subdir_package_project = TestProject() subdir_package_project.files["src/spam/spam.c"] = jinja2.Template(SPAM_C_TEMPLATE) diff --git a/test/test_testing.py b/test/test_testing.py index 39e6cd3fd..55ffa3eab 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -1,12 +1,17 @@ +from __future__ import annotations + import inspect import subprocess import textwrap -from pathlib import Path import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + project_with_a_test = test_projects.new_c_project( setup_cfg_add=textwrap.dedent( r""" diff --git a/test/test_troubleshooting.py b/test/test_troubleshooting.py index 4c4680245..2cafd6f3a 100644 --- a/test/test_troubleshooting.py +++ b/test/test_troubleshooting.py @@ -1,11 +1,16 @@ +from __future__ import annotations + import subprocess -from pathlib import Path import pytest from . import utils from .test_projects import TestProject, new_c_project +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + SO_FILE_WARNING = "NOTE: Shared object (.so) files found in this project." diff --git a/test/test_wheel_tag.py b/test/test_wheel_tag.py index 2d9859248..b74a801a0 100644 --- a/test/test_wheel_tag.py +++ b/test/test_wheel_tag.py @@ -1,9 +1,13 @@ -from pathlib import Path +from __future__ import annotations import pytest from . import test_projects, utils +TYPE_CHECKING = False +if TYPE_CHECKING: + from pathlib import Path + basic_project = test_projects.new_c_project() diff --git a/test/utils.py b/test/utils.py index d451f7509..10c3e5ceb 100644 --- a/test/utils.py +++ b/test/utils.py @@ -4,11 +4,12 @@ This file is added to the PYTHONPATH in the test runner at bin/run_test.py. """ +from __future__ import annotations + import os import platform as pm import subprocess import sys -from collections.abc import Generator, Mapping, Sequence from pathlib import Path from tempfile import TemporaryDirectory from typing import Final @@ -20,6 +21,10 @@ from cibuildwheel.selector import EnableGroup from cibuildwheel.util.file import CIBW_CACHE_PATH +TYPE_CHECKING = False +if TYPE_CHECKING: + from collections.abc import Generator, Mapping, Sequence + EMULATED_ARCHS: Final[list[str]] = sorted( arch.value for arch in (Architecture.all_archs("linux") - Architecture.auto_archs("linux")) ) diff --git a/unit_test/architecture_test.py b/unit_test/architecture_test.py index f9112f6c8..8d16b3d8f 100644 --- a/unit_test/architecture_test.py +++ b/unit_test/architecture_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import platform as platform_module import shutil import sys @@ -6,7 +8,10 @@ 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( diff --git a/unit_test/audit_test.py b/unit_test/audit_test.py index 49495d0ce..694d6e243 100644 --- a/unit_test/audit_test.py +++ b/unit_test/audit_test.py @@ -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 @@ 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( diff --git a/unit_test/download_test.py b/unit_test/download_test.py index 68c7d9262..0508b5f22 100644 --- a/unit_test/download_test.py +++ b/unit_test/download_test.py @@ -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" diff --git a/unit_test/get_platform_test.py b/unit_test/get_platform_test.py index 1cd7975e0..22bd9d053 100644 --- a/unit_test/get_platform_test.py +++ b/unit_test/get_platform_test.py @@ -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.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: diff --git a/unit_test/linux_build_steps_test.py b/unit_test/linux_build_steps_test.py index 237ab1713..42b17509b 100644 --- a/unit_test/linux_build_steps_test.py +++ b/unit_test/linux_build_steps_test.py @@ -1,13 +1,18 @@ +from __future__ import annotations + import textwrap -from pathlib import Path from pprint import pprint -import pytest - 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: """ diff --git a/unit_test/main_commands_test.py b/unit_test/main_commands_test.py index 4383fe875..d826150d4 100644 --- a/unit_test/main_commands_test.py +++ b/unit_test/main_commands_test.py @@ -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] diff --git a/unit_test/main_tests/conftest.py b/unit_test/main_tests/conftest.py index df683c67d..7242a7ebd 100644 --- a/unit_test/main_tests/conftest.py +++ b/unit_test/main_tests/conftest.py @@ -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.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: diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index 6b3701aa6..ebdce967c 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -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 @@ 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) diff --git a/unit_test/main_tests/main_platform_test.py b/unit_test/main_tests/main_platform_test.py index 51097d0e6..9d3681eb8 100644 --- a/unit_test/main_tests/main_platform_test.py +++ b/unit_test/main_tests/main_platform_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys import pytest @@ -5,10 +7,14 @@ 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", ""]) diff --git a/unit_test/main_tests/main_requires_python_test.py b/unit_test/main_tests/main_requires_python_test.py index c79688d0d..060d24f85 100644 --- a/unit_test/main_tests/main_requires_python_test.py +++ b/unit_test/main_tests/main_requires_python_test.py @@ -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) diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index 7a9fa2364..21648a20d 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import contextlib import json import os @@ -7,7 +9,6 @@ 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 @@ _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 diff --git a/unit_test/options_test.py b/unit_test/options_test.py index 4beb9c2da..8c86026da 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -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.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-*"] diff --git a/unit_test/options_toml_test.py b/unit_test/options_toml_test.py index 0689be824..d4008a2c4 100644 --- a/unit_test/options_toml_test.py +++ b/unit_test/options_toml_test.py @@ -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 @@ 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] diff --git a/unit_test/projectfiles_test.py b/unit_test/projectfiles_test.py index 3e4068df7..529ce6fd7 100644 --- a/unit_test/projectfiles_test.py +++ b/unit_test/projectfiles_test.py @@ -1,5 +1,6 @@ +from __future__ import annotations + import tomllib -from pathlib import Path from textwrap import dedent import pytest @@ -10,6 +11,10 @@ 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: From e5177eee54b115c15a5cdb116c0212d10938349f Mon Sep 17 00:00:00 2001 From: mayeut Date: Mon, 25 May 2026 09:40:09 +0200 Subject: [PATCH 2/3] chore: revert "avoid importing TYPE_CHECKING" --- bin/inspect_all_known_projects.py | 2 +- bin/projects.py | 3 +-- bin/update_pythons.py | 3 +-- cibuildwheel/__main__.py | 3 +-- cibuildwheel/_compat/tarfile.py | 2 +- cibuildwheel/architecture.py | 3 +-- cibuildwheel/audit.py | 2 +- cibuildwheel/bashlex_eval.py | 2 +- cibuildwheel/environment.py | 4 +--- cibuildwheel/extra.py | 4 +--- cibuildwheel/frontend.py | 4 +--- cibuildwheel/logger.py | 3 +-- cibuildwheel/oci_container.py | 4 +--- cibuildwheel/options.py | 4 +--- cibuildwheel/platforms/__init__.py | 4 +--- cibuildwheel/platforms/android.py | 3 +-- cibuildwheel/platforms/ios.py | 3 +-- cibuildwheel/platforms/linux.py | 3 +-- cibuildwheel/platforms/macos.py | 4 +--- cibuildwheel/platforms/pyodide.py | 3 +-- cibuildwheel/platforms/windows.py | 3 +-- cibuildwheel/projectfiles.py | 3 +-- cibuildwheel/schema.py | 2 +- cibuildwheel/selector.py | 4 +--- cibuildwheel/util/cmd.py | 3 +-- cibuildwheel/util/file.py | 3 +-- cibuildwheel/util/helpers.py | 2 +- cibuildwheel/util/packaging.py | 4 +--- cibuildwheel/util/python_build_standalone.py | 2 +- cibuildwheel/util/resources.py | 4 +--- cibuildwheel/venv.py | 4 +--- pyproject.toml | 1 - test/conftest.py | 2 +- test/test_0_basic.py | 2 +- test/test_abi3audit.py | 2 +- test/test_abi_variants.py | 2 +- test/test_before_all.py | 2 +- test/test_before_build.py | 2 +- test/test_before_test.py | 3 ++- test/test_build_frontend_args.py | 2 +- test/test_build_skip.py | 2 +- test/test_container_engine.py | 3 ++- test/test_container_images.py | 2 +- test/test_cpp_standards.py | 3 ++- test/test_custom_repair_wheel.py | 2 +- test/test_dependency_versions.py | 2 +- test/test_emulation.py | 2 +- test/test_environment.py | 2 +- test/test_from_sdist.py | 2 +- test/test_ios.py | 2 +- test/test_linux_python.py | 2 +- test/test_macos_archs.py | 2 +- test/test_manylinuxXXXX_only.py | 2 +- test/test_meson_python.py | 3 ++- test/test_musllinux_X_Y_only.py | 2 +- test/test_pep518.py | 2 +- test/test_projects/base.py | 3 +-- test/test_pure_wheel.py | 2 +- test/test_pyodide.py | 2 +- test/test_ssl.py | 2 +- test/test_subdir_package.py | 2 +- test/test_testing.py | 2 +- test/test_troubleshooting.py | 2 +- test/test_wheel_tag.py | 3 ++- test/utils.py | 3 +-- unit_test/architecture_test.py | 2 +- unit_test/audit_test.py | 2 +- unit_test/download_test.py | 2 +- unit_test/get_platform_test.py | 2 +- unit_test/linux_build_steps_test.py | 2 +- unit_test/main_commands_test.py | 2 +- unit_test/main_tests/conftest.py | 3 +-- unit_test/main_tests/main_options_test.py | 2 +- unit_test/main_tests/main_platform_test.py | 2 +- unit_test/main_tests/main_requires_python_test.py | 2 +- unit_test/oci_container_test.py | 2 +- unit_test/options_test.py | 3 +-- unit_test/options_toml_test.py | 3 +-- unit_test/projectfiles_test.py | 2 +- 79 files changed, 83 insertions(+), 119 deletions(-) diff --git a/bin/inspect_all_known_projects.py b/bin/inspect_all_known_projects.py index f328c09f0..c77494302 100755 --- a/bin/inspect_all_known_projects.py +++ b/bin/inspect_all_known_projects.py @@ -28,6 +28,7 @@ import ast from pathlib import Path +from typing import TYPE_CHECKING import click import yaml @@ -36,7 +37,6 @@ from cibuildwheel.projectfiles import Analyzer -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Iterable, Iterator diff --git a/bin/projects.py b/bin/projects.py index 1b586d29e..58ac38efb 100755 --- a/bin/projects.py +++ b/bin/projects.py @@ -28,13 +28,12 @@ from datetime import UTC, datetime from io import StringIO from pathlib import Path -from typing import Any, Self, TextIO +from typing import TYPE_CHECKING, Any, Self, TextIO import click import yaml from github import Auth, Github, GithubException -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Iterable, Mapping, Sequence diff --git a/bin/update_pythons.py b/bin/update_pythons.py index 5a8099196..d453773ce 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -20,7 +20,7 @@ import re import tomllib from pathlib import Path -from typing import Any, Final, Literal, TypedDict +from typing import TYPE_CHECKING, Any, Final, Literal, TypedDict from xml.etree import ElementTree as ET import click @@ -34,7 +34,6 @@ from cibuildwheel.extra import dump_python_configurations, get_pyodide_xbuildenv_info from cibuildwheel.platforms.android import android_triplet -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping, MutableMapping diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index c25d8bc56..272250cd1 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -12,6 +12,7 @@ import typing from pathlib import Path from tempfile import mkdtemp +from typing import TYPE_CHECKING, Any, Literal, TextIO import cibuildwheel from cibuildwheel import errors @@ -27,10 +28,8 @@ from cibuildwheel.util.helpers import strtobool from cibuildwheel.util.resources import read_all_configs -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Generator, Iterable, Sequence - from typing import Any, Literal, TextIO @dataclasses.dataclass diff --git a/cibuildwheel/_compat/tarfile.py b/cibuildwheel/_compat/tarfile.py index 4d5867d16..553073360 100644 --- a/cibuildwheel/_compat/tarfile.py +++ b/cibuildwheel/_compat/tarfile.py @@ -4,8 +4,8 @@ import sys import tarfile +from typing import TYPE_CHECKING -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 41d5ad863..359f0832d 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -7,13 +7,12 @@ import sys import typing from enum import StrEnum, auto +from typing import TYPE_CHECKING, Final, Literal, Self from cibuildwheel import errors -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Set - from typing import Final, Literal, Self from cibuildwheel.typing import PlatformName diff --git a/cibuildwheel/audit.py b/cibuildwheel/audit.py index 10f4c7cf1..8bae603e8 100644 --- a/cibuildwheel/audit.py +++ b/cibuildwheel/audit.py @@ -3,6 +3,7 @@ import subprocess import sys from pathlib import Path +from typing import TYPE_CHECKING from cibuildwheel import errors from cibuildwheel.logger import log @@ -11,7 +12,6 @@ from cibuildwheel.util.packaging import is_abi3_wheel from cibuildwheel.venv import activate_virtualenv, find_uv, virtualenv -TYPE_CHECKING = False if TYPE_CHECKING: from cibuildwheel.options import BuildOptions diff --git a/cibuildwheel/bashlex_eval.py b/cibuildwheel/bashlex_eval.py index 85cdcb1ad..d76040524 100644 --- a/cibuildwheel/bashlex_eval.py +++ b/cibuildwheel/bashlex_eval.py @@ -2,10 +2,10 @@ import dataclasses import subprocess +from typing import TYPE_CHECKING import bashlex -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import ( Callable, diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index bc5d13bf0..47d2585dc 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -1,17 +1,15 @@ from __future__ import annotations import dataclasses -from typing import Protocol +from typing import TYPE_CHECKING, Any, Protocol import bashlex import bashlex.errors from cibuildwheel import bashlex_eval -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping, Sequence - from typing import Any class EnvironmentParseError(Exception): diff --git a/cibuildwheel/extra.py b/cibuildwheel/extra.py index d07e7784b..9e9a57a30 100644 --- a/cibuildwheel/extra.py +++ b/cibuildwheel/extra.py @@ -10,14 +10,12 @@ import urllib.error import urllib.request from io import StringIO -from typing import NotRequired, Protocol +from typing import TYPE_CHECKING, Any, NotRequired, Protocol from cibuildwheel import __version__ as cibw_version -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping, Sequence - from typing import Any __all__ = ("Printable", "dump_python_configurations") diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index 463570346..b7f6654d7 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -3,14 +3,12 @@ import dataclasses import shlex import typing -from typing import Literal, get_args +from typing import TYPE_CHECKING, Literal, Self, get_args from cibuildwheel.util.helpers import parse_key_value_string, prepare_command -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Sequence - from typing import Self from cibuildwheel.typing import PathOrStr diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index da33370e8..f7381f15f 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -12,15 +12,14 @@ import textwrap import time from pathlib import Path +from typing import IO, TYPE_CHECKING, AnyStr, Final, Literal import humanize from cibuildwheel.ci import CIProvider, detect_ci_provider, filter_ansi_codes -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Generator - from typing import IO, AnyStr, Final, Literal from cibuildwheel.options import Options diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index a95ed5215..fc07f300a 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -14,7 +14,7 @@ import uuid from enum import Enum from pathlib import PurePosixPath -from typing import Literal, assert_never +from typing import IO, TYPE_CHECKING, Literal, Self, assert_never from cibuildwheel.ci import CIProvider, detect_ci_provider from cibuildwheel.errors import OCIEngineTooOldError @@ -22,12 +22,10 @@ from cibuildwheel.util.cmd import call from cibuildwheel.util.helpers import FlexibleVersion, parse_key_value_string, strtobool -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping, Sequence from pathlib import Path, PurePath from types import TracebackType - from typing import IO, Self from cibuildwheel.typing import PathOrStr diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index 89b646812..d4c55e5b5 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -12,7 +12,7 @@ import tomllib from collections.abc import Mapping, Sequence from pathlib import Path -from typing import assert_never +from typing import TYPE_CHECKING, Any, Final, Literal, Self, assert_never from packaging.specifiers import SpecifierSet @@ -29,10 +29,8 @@ from cibuildwheel.util.helpers import format_safe, parse_key_value_string, strtobool, unwrap from cibuildwheel.util.packaging import DependencyConstraints -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Callable, Generator, Iterable, Set - from typing import Any, Final, Literal, Self MANYLINUX_ARCHS: Final[tuple[str, ...]] = ( "x86_64", diff --git a/cibuildwheel/platforms/__init__.py b/cibuildwheel/platforms/__init__.py index cfe22cbba..cb31b0c8b 100644 --- a/cibuildwheel/platforms/__init__.py +++ b/cibuildwheel/platforms/__init__.py @@ -1,16 +1,14 @@ from __future__ import annotations import sys -from typing import Protocol +from typing import TYPE_CHECKING, Final, Protocol from cibuildwheel import errors from cibuildwheel.platforms import android, ios, linux, macos, pyodide, windows -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Sequence from pathlib import Path - from typing import Final from cibuildwheel.architecture import Architecture from cibuildwheel.options import Options diff --git a/cibuildwheel/platforms/android.py b/cibuildwheel/platforms/android.py index b8bd4bf56..df8876d58 100644 --- a/cibuildwheel/platforms/android.py +++ b/cibuildwheel/platforms/android.py @@ -15,7 +15,7 @@ from pprint import pprint from runpy import run_path from textwrap import dedent -from typing import Any +from typing import TYPE_CHECKING, Any from build import ProjectBuilder from build.env import IsolatedEnv @@ -40,7 +40,6 @@ from cibuildwheel.util.python_build_standalone import create_python_build_standalone_environment from cibuildwheel.venv import constraint_flags, find_uv, virtualenv -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Iterable, Iterator, MutableMapping diff --git a/cibuildwheel/platforms/ios.py b/cibuildwheel/platforms/ios.py index 225662e15..7cb31d9b1 100644 --- a/cibuildwheel/platforms/ios.py +++ b/cibuildwheel/platforms/ios.py @@ -9,7 +9,7 @@ import sys import textwrap from pathlib import Path -from typing import assert_never +from typing import TYPE_CHECKING, assert_never from filelock import FileLock @@ -29,7 +29,6 @@ from cibuildwheel.util.packaging import find_compatible_wheel from cibuildwheel.venv import constraint_flags, virtualenv -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Sequence, Set diff --git a/cibuildwheel/platforms/linux.py b/cibuildwheel/platforms/linux.py index 9b4559bac..c00e3c0b4 100644 --- a/cibuildwheel/platforms/linux.py +++ b/cibuildwheel/platforms/linux.py @@ -8,7 +8,7 @@ import textwrap from collections import OrderedDict from pathlib import Path, PurePath, PurePosixPath -from typing import assert_never +from typing import TYPE_CHECKING, assert_never from cibuildwheel import errors from cibuildwheel.architecture import Architecture @@ -21,7 +21,6 @@ from cibuildwheel.util.helpers import prepare_command, unwrap from cibuildwheel.util.packaging import find_compatible_wheel -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Iterable, Iterator, Sequence, Set diff --git a/cibuildwheel/platforms/macos.py b/cibuildwheel/platforms/macos.py index 3208bcd1a..ae3bd178a 100644 --- a/cibuildwheel/platforms/macos.py +++ b/cibuildwheel/platforms/macos.py @@ -11,7 +11,7 @@ import sys import typing from pathlib import Path -from typing import assert_never +from typing import TYPE_CHECKING, Literal, assert_never from filelock import FileLock from packaging.version import Version @@ -32,10 +32,8 @@ from cibuildwheel.util.packaging import find_compatible_wheel, get_pip_version from cibuildwheel.venv import constraint_flags, find_uv, target_marker_env, virtualenv -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Set - from typing import Literal from cibuildwheel.architecture import Architecture from cibuildwheel.environment import ParsedEnvironment diff --git a/cibuildwheel/platforms/pyodide.py b/cibuildwheel/platforms/pyodide.py index 53c66d9f8..9e03e5fb1 100644 --- a/cibuildwheel/platforms/pyodide.py +++ b/cibuildwheel/platforms/pyodide.py @@ -11,7 +11,7 @@ import typing from pathlib import Path from tempfile import TemporaryDirectory -from typing import Final, TypedDict +from typing import TYPE_CHECKING, Final, TypedDict from filelock import FileLock @@ -38,7 +38,6 @@ ) from cibuildwheel.venv import constraint_flags, virtualenv -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Set diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index 8b30c710c..7dc48e412 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -9,7 +9,7 @@ import textwrap from functools import cache from pathlib import Path -from typing import assert_never +from typing import TYPE_CHECKING, assert_never from filelock import FileLock @@ -35,7 +35,6 @@ from cibuildwheel.util.packaging import find_compatible_wheel, get_pip_version from cibuildwheel.venv import constraint_flags, find_uv, target_marker_env, virtualenv -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import MutableMapping, Sequence, Set diff --git a/cibuildwheel/projectfiles.py b/cibuildwheel/projectfiles.py index 41af8b1f7..43b7a1a94 100644 --- a/cibuildwheel/projectfiles.py +++ b/cibuildwheel/projectfiles.py @@ -3,13 +3,12 @@ import ast import configparser import contextlib +from typing import TYPE_CHECKING, Any import dependency_groups -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path - from typing import Any def get_parent(node: ast.AST | None, depth: int = 1) -> ast.AST | None: diff --git a/cibuildwheel/schema.py b/cibuildwheel/schema.py index dde0efcc1..6bbf0d011 100644 --- a/cibuildwheel/schema.py +++ b/cibuildwheel/schema.py @@ -1,10 +1,10 @@ from __future__ import annotations import json +from typing import TYPE_CHECKING from cibuildwheel.util import resources -TYPE_CHECKING = False if TYPE_CHECKING: from typing import Any diff --git a/cibuildwheel/selector.py b/cibuildwheel/selector.py index e9fa8c130..865ada814 100644 --- a/cibuildwheel/selector.py +++ b/cibuildwheel/selector.py @@ -4,14 +4,12 @@ import itertools from enum import StrEnum from fnmatch import fnmatch +from typing import TYPE_CHECKING, Self import bracex from packaging.version import Version -TYPE_CHECKING = False if TYPE_CHECKING: - from typing import Self - from packaging.specifiers import SpecifierSet diff --git a/cibuildwheel/util/cmd.py b/cibuildwheel/util/cmd.py index ed864c275..8dd05d620 100644 --- a/cibuildwheel/util/cmd.py +++ b/cibuildwheel/util/cmd.py @@ -6,13 +6,12 @@ import subprocess import sys import typing +from typing import TYPE_CHECKING, Final, Literal from cibuildwheel.errors import FatalError -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Iterator, Mapping - from typing import Final, Literal from cibuildwheel.typing import PathOrStr diff --git a/cibuildwheel/util/file.py b/cibuildwheel/util/file.py index eaec26486..dfd3992c7 100644 --- a/cibuildwheel/util/file.py +++ b/cibuildwheel/util/file.py @@ -7,7 +7,7 @@ import time import urllib.request from pathlib import Path, PurePath -from typing import Final +from typing import TYPE_CHECKING, Final from zipfile import ZipFile import certifi @@ -15,7 +15,6 @@ from cibuildwheel.errors import FatalError -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Callable diff --git a/cibuildwheel/util/helpers.py b/cibuildwheel/util/helpers.py index 6eb79a959..40692864b 100644 --- a/cibuildwheel/util/helpers.py +++ b/cibuildwheel/util/helpers.py @@ -6,8 +6,8 @@ import shlex import textwrap from collections import defaultdict +from typing import TYPE_CHECKING -TYPE_CHECKING = False if TYPE_CHECKING: import os from collections.abc import Sequence diff --git a/cibuildwheel/util/packaging.py b/cibuildwheel/util/packaging.py index d8bb57c66..0c64b573d 100644 --- a/cibuildwheel/util/packaging.py +++ b/cibuildwheel/util/packaging.py @@ -3,7 +3,7 @@ import shlex from dataclasses import dataclass, field from pathlib import Path, PurePath -from typing import TypeVar +from typing import TYPE_CHECKING, Literal, Self, TypeVar from packaging.utils import parse_wheel_filename @@ -11,10 +11,8 @@ from cibuildwheel.util.cmd import call from cibuildwheel.util.helpers import parse_key_value_string, unwrap -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping, Sequence - from typing import Literal, Self @dataclass(kw_only=True) diff --git a/cibuildwheel/util/python_build_standalone.py b/cibuildwheel/util/python_build_standalone.py index f6f9897e0..1a9ac310b 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -5,13 +5,13 @@ import json import platform import typing +from typing import TYPE_CHECKING from filelock import FileLock from cibuildwheel.util.file import download, extract_tar from cibuildwheel.util.resources import PYTHON_BUILD_STANDALONE_RELEASES -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/cibuildwheel/util/resources.py b/cibuildwheel/util/resources.py index 0ac9e8f98..54222aaf2 100644 --- a/cibuildwheel/util/resources.py +++ b/cibuildwheel/util/resources.py @@ -3,11 +3,9 @@ import functools import tomllib from pathlib import Path +from typing import TYPE_CHECKING, Final -TYPE_CHECKING = False if TYPE_CHECKING: - from typing import Final - from cibuildwheel.typing import PlatformName PATH: Final[Path] = Path(__file__).parent.parent / "resources" diff --git a/cibuildwheel/venv.py b/cibuildwheel/venv.py index 91c21f069..97b093da5 100644 --- a/cibuildwheel/venv.py +++ b/cibuildwheel/venv.py @@ -7,7 +7,7 @@ import sys import tomllib from pathlib import Path -from typing import cast +from typing import TYPE_CHECKING, Final, cast from filelock import FileLock from packaging.markers import default_environment @@ -18,10 +18,8 @@ from cibuildwheel.util.cmd import call from cibuildwheel.util.file import CIBW_CACHE_PATH, download -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Sequence - from typing import Final _IS_WIN: Final[bool] = sys.platform.startswith("win") diff --git a/pyproject.toml b/pyproject.toml index e10a6b55a..b31b58e1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -232,7 +232,6 @@ future-annotations = true "typing.Iterator".msg = "Use collections.abc.Iterator instead." "typing.Sequence".msg = "Use collections.abc.Sequence instead." "typing.Set".msg = "Use collections.abc.Set instead." -"typing.TYPE_CHECKING".msg = "Use TYPE_CHECKING=False instead" [tool.ruff.lint.per-file-ignores] "unit_test/*" = ["PLC1901", "TID252"] diff --git a/test/conftest.py b/test/conftest.py index 15d2f57f2..50dcf2b1c 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,6 +3,7 @@ import json import os import subprocess +from typing import TYPE_CHECKING import pytest from filelock import FileLock @@ -17,7 +18,6 @@ from . import utils from .utils import DEFAULT_CIBW_ENABLE, EMULATED_ARCHS, get_platform -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Generator diff --git a/test/test_0_basic.py b/test/test_0_basic.py index 8c1d9b75d..fca7b7adc 100644 --- a/test/test_0_basic.py +++ b/test/test_0_basic.py @@ -1,6 +1,7 @@ from __future__ import annotations import textwrap +from typing import TYPE_CHECKING import packaging.utils import pytest @@ -10,7 +11,6 @@ from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_abi3audit.py b/test/test_abi3audit.py index 1a38fc32d..5abdcba7a 100644 --- a/test/test_abi3audit.py +++ b/test/test_abi3audit.py @@ -2,12 +2,12 @@ import subprocess import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_abi_variants.py b/test/test_abi_variants.py index b89f8c763..fc92668c5 100644 --- a/test/test_abi_variants.py +++ b/test/test_abi_variants.py @@ -1,10 +1,10 @@ from __future__ import annotations import textwrap +from typing import TYPE_CHECKING from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_before_all.py b/test/test_before_all.py index 2f36f38f5..0e5b353d2 100644 --- a/test/test_before_all.py +++ b/test/test_before_all.py @@ -2,12 +2,12 @@ import subprocess import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_before_build.py b/test/test_before_build.py index 6986591c3..6587621be 100644 --- a/test/test_before_build.py +++ b/test/test_before_build.py @@ -2,12 +2,12 @@ import subprocess import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_before_test.py b/test/test_before_test.py index ee0cef734..da8100eeb 100644 --- a/test/test_before_test.py +++ b/test/test_before_test.py @@ -1,8 +1,9 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_build_frontend_args.py b/test/test_build_frontend_args.py index 3c1aa6a2c..b889efefa 100644 --- a/test/test_build_frontend_args.py +++ b/test/test_build_frontend_args.py @@ -1,12 +1,12 @@ from __future__ import annotations import subprocess +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_build_skip.py b/test/test_build_skip.py index f6dfcaae0..b0e689c3b 100644 --- a/test/test_build_skip.py +++ b/test/test_build_skip.py @@ -1,10 +1,10 @@ from __future__ import annotations import textwrap +from typing import TYPE_CHECKING from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_container_engine.py b/test/test_container_engine.py index 34f6a151e..f616cf64e 100644 --- a/test/test_container_engine.py +++ b/test/test_container_engine.py @@ -1,10 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_container_images.py b/test/test_container_images.py index 5c044cdcb..7d9684782 100644 --- a/test/test_container_images.py +++ b/test/test_container_images.py @@ -2,12 +2,12 @@ import platform import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_cpp_standards.py b/test/test_cpp_standards.py index 07bb5ddde..4a1e170cb 100644 --- a/test/test_cpp_standards.py +++ b/test/test_cpp_standards.py @@ -1,11 +1,12 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import jinja2 from . import utils from .test_projects import TestProject -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_custom_repair_wheel.py b/test/test_custom_repair_wheel.py index 5f5f9a493..e5b077836 100644 --- a/test/test_custom_repair_wheel.py +++ b/test/test_custom_repair_wheel.py @@ -3,6 +3,7 @@ import subprocess import textwrap from contextlib import nullcontext as does_not_raise +from typing import TYPE_CHECKING import pytest @@ -10,7 +11,6 @@ from . import utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index 714ecf90a..0da86c386 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -4,6 +4,7 @@ import re import subprocess import textwrap +from typing import TYPE_CHECKING import pytest @@ -11,7 +12,6 @@ from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_emulation.py b/test/test_emulation.py index 3c6aa6d6b..202e8e3ea 100644 --- a/test/test_emulation.py +++ b/test/test_emulation.py @@ -2,12 +2,12 @@ import itertools import subprocess +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_environment.py b/test/test_environment.py index aa56bb44d..552c13cbb 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -4,12 +4,12 @@ import subprocess import sys import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_from_sdist.py b/test/test_from_sdist.py index 775b81bcd..1be57b0f9 100644 --- a/test/test_from_sdist.py +++ b/test/test_from_sdist.py @@ -6,10 +6,10 @@ import textwrap from pathlib import Path from tempfile import TemporaryDirectory +from typing import TYPE_CHECKING from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping diff --git a/test/test_ios.py b/test/test_ios.py index d36437d91..97270cefb 100644 --- a/test/test_ios.py +++ b/test/test_ios.py @@ -5,12 +5,12 @@ import shutil import subprocess import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_linux_python.py b/test/test_linux_python.py index 0fa33967e..e0308625e 100644 --- a/test/test_linux_python.py +++ b/test/test_linux_python.py @@ -2,12 +2,12 @@ import platform import subprocess +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_macos_archs.py b/test/test_macos_archs.py index 6cbecb130..ae00a51a6 100644 --- a/test/test_macos_archs.py +++ b/test/test_macos_archs.py @@ -1,12 +1,12 @@ from __future__ import annotations import platform +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_manylinuxXXXX_only.py b/test/test_manylinuxXXXX_only.py index 135e33eee..e58c36461 100644 --- a/test/test_manylinuxXXXX_only.py +++ b/test/test_manylinuxXXXX_only.py @@ -2,12 +2,12 @@ import platform import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_meson_python.py b/test/test_meson_python.py index 7c49b615b..62dd42406 100644 --- a/test/test_meson_python.py +++ b/test/test_meson_python.py @@ -1,10 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import packaging.utils from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_musllinux_X_Y_only.py b/test/test_musllinux_X_Y_only.py index b9dde2565..ed3b67785 100644 --- a/test/test_musllinux_X_Y_only.py +++ b/test/test_musllinux_X_Y_only.py @@ -1,12 +1,12 @@ from __future__ import annotations import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_pep518.py b/test/test_pep518.py index 4bd74b2db..a5b24c918 100644 --- a/test/test_pep518.py +++ b/test/test_pep518.py @@ -2,10 +2,10 @@ import textwrap from pathlib import Path +from typing import TYPE_CHECKING from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_projects/base.py b/test/test_projects/base.py index c168345e9..e56f07881 100644 --- a/test/test_projects/base.py +++ b/test/test_projects/base.py @@ -1,10 +1,9 @@ from __future__ import annotations -from typing import Any, Self +from typing import TYPE_CHECKING, Any, Self import jinja2 -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_pure_wheel.py b/test/test_pure_wheel.py index 300e44f05..6b0752e2a 100644 --- a/test/test_pure_wheel.py +++ b/test/test_pure_wheel.py @@ -2,6 +2,7 @@ import subprocess from pathlib import Path +from typing import TYPE_CHECKING import pytest @@ -9,7 +10,6 @@ from . import utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_pyodide.py b/test/test_pyodide.py index 008adb1ec..3e90d6285 100644 --- a/test/test_pyodide.py +++ b/test/test_pyodide.py @@ -5,6 +5,7 @@ import subprocess import sys import textwrap +from typing import TYPE_CHECKING import pytest @@ -12,7 +13,6 @@ from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_ssl.py b/test/test_ssl.py index b8e8b3f33..8465a9d62 100644 --- a/test/test_ssl.py +++ b/test/test_ssl.py @@ -1,12 +1,12 @@ from __future__ import annotations import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_subdir_package.py b/test/test_subdir_package.py index 83cec17f1..656671195 100644 --- a/test/test_subdir_package.py +++ b/test/test_subdir_package.py @@ -1,6 +1,7 @@ from __future__ import annotations from pathlib import Path +from typing import TYPE_CHECKING import jinja2 @@ -8,7 +9,6 @@ from .test_projects import TestProject from .test_projects.c import SPAM_C_TEMPLATE -TYPE_CHECKING = False if TYPE_CHECKING: import pytest diff --git a/test/test_testing.py b/test/test_testing.py index 55ffa3eab..118f3b0dd 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -3,12 +3,12 @@ import inspect import subprocess import textwrap +from typing import TYPE_CHECKING import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_troubleshooting.py b/test/test_troubleshooting.py index 2cafd6f3a..f12f55ea8 100644 --- a/test/test_troubleshooting.py +++ b/test/test_troubleshooting.py @@ -1,13 +1,13 @@ from __future__ import annotations import subprocess +from typing import TYPE_CHECKING import pytest from . import utils from .test_projects import TestProject, new_c_project -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/test_wheel_tag.py b/test/test_wheel_tag.py index b74a801a0..4f53f1a6b 100644 --- a/test/test_wheel_tag.py +++ b/test/test_wheel_tag.py @@ -1,10 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + import pytest from . import test_projects, utils -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/test/utils.py b/test/utils.py index 10c3e5ceb..1d9502191 100644 --- a/test/utils.py +++ b/test/utils.py @@ -12,7 +12,7 @@ import sys from pathlib import Path from tempfile import TemporaryDirectory -from typing import Final +from typing import TYPE_CHECKING, Final import pytest @@ -21,7 +21,6 @@ from cibuildwheel.selector import EnableGroup from cibuildwheel.util.file import CIBW_CACHE_PATH -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Generator, Mapping, Sequence diff --git a/unit_test/architecture_test.py b/unit_test/architecture_test.py index 8d16b3d8f..907e4f063 100644 --- a/unit_test/architecture_test.py +++ b/unit_test/architecture_test.py @@ -3,13 +3,13 @@ import platform as platform_module import shutil import sys +from typing import TYPE_CHECKING import pytest import cibuildwheel.architecture from cibuildwheel.architecture import Architecture, arch_synonym -TYPE_CHECKING = False if TYPE_CHECKING: from cibuildwheel.typing import PlatformName diff --git a/unit_test/audit_test.py b/unit_test/audit_test.py index 694d6e243..833cf1d2a 100644 --- a/unit_test/audit_test.py +++ b/unit_test/audit_test.py @@ -2,6 +2,7 @@ import subprocess from pathlib import Path +from typing import TYPE_CHECKING from unittest.mock import Mock, patch import pytest @@ -9,7 +10,6 @@ from cibuildwheel import errors from cibuildwheel.audit import needs_audit, run_audit -TYPE_CHECKING = False if TYPE_CHECKING: import contextlib diff --git a/unit_test/download_test.py b/unit_test/download_test.py index 0508b5f22..8e42b62e0 100644 --- a/unit_test/download_test.py +++ b/unit_test/download_test.py @@ -1,13 +1,13 @@ from __future__ import annotations import ssl +from typing import TYPE_CHECKING import certifi import pytest from cibuildwheel.util.file import download -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/unit_test/get_platform_test.py b/unit_test/get_platform_test.py index 22bd9d053..efd1352d2 100644 --- a/unit_test/get_platform_test.py +++ b/unit_test/get_platform_test.py @@ -2,6 +2,7 @@ import contextlib import sys +from typing import TYPE_CHECKING import pytest import setuptools._distutils.util @@ -10,7 +11,6 @@ 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 diff --git a/unit_test/linux_build_steps_test.py b/unit_test/linux_build_steps_test.py index 42b17509b..16101d475 100644 --- a/unit_test/linux_build_steps_test.py +++ b/unit_test/linux_build_steps_test.py @@ -2,12 +2,12 @@ import textwrap from pprint import pprint +from typing import TYPE_CHECKING 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 diff --git a/unit_test/main_commands_test.py b/unit_test/main_commands_test.py index d826150d4..6eb52ff40 100644 --- a/unit_test/main_commands_test.py +++ b/unit_test/main_commands_test.py @@ -3,13 +3,13 @@ import errno import shutil import sys +from typing import TYPE_CHECKING import pytest import cibuildwheel.__main__ as main_module from cibuildwheel.__main__ import main -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/unit_test/main_tests/conftest.py b/unit_test/main_tests/conftest.py index 7242a7ebd..e20aaed37 100644 --- a/unit_test/main_tests/conftest.py +++ b/unit_test/main_tests/conftest.py @@ -5,7 +5,7 @@ import subprocess import sys from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any import pytest @@ -14,7 +14,6 @@ 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 diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index ebdce967c..21f2e2b00 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -4,6 +4,7 @@ import tomllib from fnmatch import fnmatch from pathlib import Path +from typing import TYPE_CHECKING import pytest @@ -15,7 +16,6 @@ from cibuildwheel.util import resources from cibuildwheel.util.packaging import DependencyConstraints -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Mapping diff --git a/unit_test/main_tests/main_platform_test.py b/unit_test/main_tests/main_platform_test.py index 9d3681eb8..fce33b339 100644 --- a/unit_test/main_tests/main_platform_test.py +++ b/unit_test/main_tests/main_platform_test.py @@ -1,6 +1,7 @@ from __future__ import annotations import sys +from typing import TYPE_CHECKING import pytest @@ -10,7 +11,6 @@ from ..conftest import MOCK_PACKAGE_DIR -TYPE_CHECKING = False if TYPE_CHECKING: from cibuildwheel.typing import PlatformName diff --git a/unit_test/main_tests/main_requires_python_test.py b/unit_test/main_tests/main_requires_python_test.py index 060d24f85..4e1e82ce0 100644 --- a/unit_test/main_tests/main_requires_python_test.py +++ b/unit_test/main_tests/main_requires_python_test.py @@ -2,13 +2,13 @@ import sys import textwrap +from typing import TYPE_CHECKING import pytest from packaging.specifiers import SpecifierSet from cibuildwheel.__main__ import main -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index 21648a20d..90fe39e14 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -11,6 +11,7 @@ import time from contextlib import nullcontext from pathlib import Path, PurePath, PurePosixPath +from typing import TYPE_CHECKING import pytest import tomli_w @@ -26,7 +27,6 @@ _check_engine_version, ) -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Iterator diff --git a/unit_test/options_test.py b/unit_test/options_test.py index 8c86026da..a6f13535c 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -5,7 +5,7 @@ import textwrap import unittest.mock from pathlib import Path -from typing import Literal +from typing import TYPE_CHECKING, Literal import pytest @@ -26,7 +26,6 @@ from cibuildwheel.util import resources from cibuildwheel.util.packaging import DependencyConstraints -TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Sequence diff --git a/unit_test/options_toml_test.py b/unit_test/options_toml_test.py index d4008a2c4..a65143433 100644 --- a/unit_test/options_toml_test.py +++ b/unit_test/options_toml_test.py @@ -1,7 +1,7 @@ from __future__ import annotations import shlex -from typing import Any, cast +from typing import TYPE_CHECKING, Any, cast import pytest @@ -15,7 +15,6 @@ _resolve_cascade, ) -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path diff --git a/unit_test/projectfiles_test.py b/unit_test/projectfiles_test.py index 529ce6fd7..ba25ae72c 100644 --- a/unit_test/projectfiles_test.py +++ b/unit_test/projectfiles_test.py @@ -2,6 +2,7 @@ import tomllib from textwrap import dedent +from typing import TYPE_CHECKING import pytest @@ -11,7 +12,6 @@ setup_py_python_requires, ) -TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path From f0ff050f4558771858129b8653da7ac2049f5801 Mon Sep 17 00:00:00 2001 From: mayeut Date: Mon, 25 May 2026 10:28:28 +0200 Subject: [PATCH 3/3] chore: do not enforce TYPE_CHECKING blocks for tests --- pyproject.toml | 4 ++-- test/conftest.py | 7 +------ test/test_0_basic.py | 7 +------ test/test_abi3audit.py | 7 +------ test/test_abi_variants.py | 11 +++-------- test/test_before_all.py | 7 +------ test/test_before_build.py | 7 +------ test/test_before_test.py | 7 +------ test/test_build_frontend_args.py | 7 +------ test/test_build_skip.py | 7 +------ test/test_container_engine.py | 7 +------ test/test_container_images.py | 7 +------ test/test_cpp_standards.py | 7 +------ test/test_custom_repair_wheel.py | 7 +------ test/test_dependency_versions.py | 7 +------ test/test_emulation.py | 7 +------ test/test_environment.py | 7 +------ test/test_from_sdist.py | 13 ++++--------- test/test_ios.py | 7 +------ test/test_linux_python.py | 7 +------ test/test_macos_archs.py | 7 +------ test/test_manylinuxXXXX_only.py | 7 +------ test/test_meson_python.py | 7 +------ test/test_musllinux_X_Y_only.py | 7 +------ test/test_pep518.py | 6 ------ test/test_projects/base.py | 8 ++------ test/test_pure_wheel.py | 6 ------ test/test_pyodide.py | 7 +------ test/test_ssl.py | 7 +------ test/test_subdir_package.py | 7 +------ test/test_testing.py | 7 +------ test/test_troubleshooting.py | 7 +------ test/test_wheel_tag.py | 7 +------ test/utils.py | 8 ++------ unit_test/architecture_test.py | 7 +------ unit_test/audit_test.py | 7 +------ unit_test/download_test.py | 7 +------ unit_test/get_platform_test.py | 9 +++------ unit_test/linux_build_steps_test.py | 11 +++-------- unit_test/main_commands_test.py | 7 +------ unit_test/main_tests/conftest.py | 8 ++------ unit_test/main_tests/main_options_test.py | 5 ++--- unit_test/main_tests/main_platform_test.py | 10 ++-------- unit_test/main_tests/main_requires_python_test.py | 9 ++------- unit_test/oci_container_test.py | 7 +------ unit_test/options_test.py | 8 ++------ unit_test/options_toml_test.py | 11 +++-------- unit_test/projectfiles_test.py | 7 +------ 48 files changed, 65 insertions(+), 293 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b31b58e1f..80f8cefc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -234,8 +234,8 @@ future-annotations = true "typing.Set".msg = "Use collections.abc.Set instead." [tool.ruff.lint.per-file-ignores] -"unit_test/*" = ["PLC1901", "TID252"] -"test/*" = ["TID252"] +"unit_test/*" = ["PLC1901", "TC", "TID252"] +"test/*" = ["TC", "TID252"] "bin/*" = ["TID251"] "cibuildwheel/resources/install_certifi.py" = ["PTH"] diff --git a/test/conftest.py b/test/conftest.py index 50dcf2b1c..8949dc80d 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,9 +1,7 @@ -from __future__ import annotations - import json import os import subprocess -from typing import TYPE_CHECKING +from collections.abc import Generator import pytest from filelock import FileLock @@ -18,9 +16,6 @@ from . import utils from .utils import DEFAULT_CIBW_ENABLE, EMULATED_ARCHS, get_platform -if TYPE_CHECKING: - from collections.abc import Generator - def pytest_addoption(parser: pytest.Parser) -> None: parser.addoption( diff --git a/test/test_0_basic.py b/test/test_0_basic.py index fca7b7adc..ec9b6f166 100644 --- a/test/test_0_basic.py +++ b/test/test_0_basic.py @@ -1,7 +1,5 @@ -from __future__ import annotations - import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import packaging.utils import pytest @@ -11,9 +9,6 @@ from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - basic_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( """ diff --git a/test/test_abi3audit.py b/test/test_abi3audit.py index 5abdcba7a..adacf25c5 100644 --- a/test/test_abi3audit.py +++ b/test/test_abi3audit.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import subprocess import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - pyproject_toml = r""" [build-system] requires = ["setuptools", "wheel"] diff --git a/test/test_abi_variants.py b/test/test_abi_variants.py index fc92668c5..bf0907a35 100644 --- a/test/test_abi_variants.py +++ b/test/test_abi_variants.py @@ -1,14 +1,9 @@ -from __future__ import annotations - import textwrap -from typing import TYPE_CHECKING - -from . import test_projects, utils +from pathlib import Path -if TYPE_CHECKING: - from pathlib import Path +import pytest - import pytest +from . import test_projects, utils pyproject_toml = r""" [build-system] diff --git a/test/test_before_all.py b/test/test_before_all.py index 0e5b353d2..156b38507 100644 --- a/test/test_before_all.py +++ b/test/test_before_all.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import subprocess import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_before_build_asserts = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_before_build.py b/test/test_before_build.py index 6587621be..37cbe9ace 100644 --- a/test/test_before_build.py +++ b/test/test_before_build.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import subprocess import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - # pyodide does not support building without isolation, need to check the base_prefix SYS_PREFIX = f"sys.{'base_' if utils.get_platform() == 'pyodide' else ''}prefix" diff --git a/test/test_before_test.py b/test/test_before_test.py index da8100eeb..d067edd7a 100644 --- a/test/test_before_test.py +++ b/test/test_before_test.py @@ -1,12 +1,7 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING +from pathlib import Path from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - before_test_project = test_projects.new_c_project() before_test_project.files["test/spam_test.py"] = r""" import sys diff --git a/test/test_build_frontend_args.py b/test/test_build_frontend_args.py index b889efefa..4940e02fc 100644 --- a/test/test_build_frontend_args.py +++ b/test/test_build_frontend_args.py @@ -1,15 +1,10 @@ -from __future__ import annotations - import subprocess -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - @pytest.mark.parametrize( "frontend_name", diff --git a/test/test_build_skip.py b/test/test_build_skip.py index b0e689c3b..d9b1bf32d 100644 --- a/test/test_build_skip.py +++ b/test/test_build_skip.py @@ -1,13 +1,8 @@ -from __future__ import annotations - import textwrap -from typing import TYPE_CHECKING +from pathlib import Path from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_skip_asserts = test_projects.new_c_project( setup_py_add=textwrap.dedent( rf""" diff --git a/test/test_container_engine.py b/test/test_container_engine.py index f616cf64e..68968dfdc 100644 --- a/test/test_container_engine.py +++ b/test/test_container_engine.py @@ -1,14 +1,9 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - basic_project = test_projects.new_c_project() diff --git a/test/test_container_images.py b/test/test_container_images.py index 7d9684782..fa8bc5181 100644 --- a/test/test_container_images.py +++ b/test/test_container_images.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import platform import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - dockcross_only_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_cpp_standards.py b/test/test_cpp_standards.py index 4a1e170cb..deba8e645 100644 --- a/test/test_cpp_standards.py +++ b/test/test_cpp_standards.py @@ -1,15 +1,10 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING +from pathlib import Path import jinja2 from . import utils from .test_projects import TestProject -if TYPE_CHECKING: - from pathlib import Path - cpp_test_project = TestProject() setup_py_template = r""" diff --git a/test/test_custom_repair_wheel.py b/test/test_custom_repair_wheel.py index e5b077836..8bfe6a3fa 100644 --- a/test/test_custom_repair_wheel.py +++ b/test/test_custom_repair_wheel.py @@ -1,9 +1,7 @@ -from __future__ import annotations - import subprocess import textwrap from contextlib import nullcontext as does_not_raise -from typing import TYPE_CHECKING +from pathlib import Path import pytest @@ -11,9 +9,6 @@ from . import utils -if TYPE_CHECKING: - from pathlib import Path - basic_project = test_projects.new_c_project() basic_project.files["repair.py"] = """ import shutil diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index 0da86c386..974624018 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -1,10 +1,8 @@ -from __future__ import annotations - import json import re import subprocess import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest @@ -12,9 +10,6 @@ from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - VERSION_REGEX = r"([\w-]+)==([^;\s]+)" CHECK_VERSIONS_SCRIPT = """\ diff --git a/test/test_emulation.py b/test/test_emulation.py index 202e8e3ea..b475b6a73 100644 --- a/test/test_emulation.py +++ b/test/test_emulation.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import itertools import subprocess -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_a_test = test_projects.new_c_project() project_with_a_test.files["test/spam_test.py"] = r""" diff --git a/test/test_environment.py b/test/test_environment.py index 552c13cbb..b12a89999 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -1,18 +1,13 @@ -from __future__ import annotations - import os import subprocess import sys import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_environment_asserts = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_from_sdist.py b/test/test_from_sdist.py index 1be57b0f9..094e96d8c 100644 --- a/test/test_from_sdist.py +++ b/test/test_from_sdist.py @@ -1,21 +1,16 @@ -from __future__ import annotations - import os import subprocess import sys import textwrap +from collections.abc import Mapping from pathlib import Path from tempfile import TemporaryDirectory -from typing import TYPE_CHECKING - -from . import test_projects, utils -if TYPE_CHECKING: - from collections.abc import Mapping +import pytest - import pytest +from test.test_projects.base import TestProject - from test.test_projects.base import TestProject +from . import test_projects, utils # utilities diff --git a/test/test_ios.py b/test/test_ios.py index 97270cefb..b0739d587 100644 --- a/test/test_ios.py +++ b/test/test_ios.py @@ -1,19 +1,14 @@ -from __future__ import annotations - import os import platform import shutil import subprocess import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - pytestmark = pytest.mark.ios CIBW_PLATFORM = os.environ.get("CIBW_PLATFORM", "ios") diff --git a/test/test_linux_python.py b/test/test_linux_python.py index e0308625e..d0f93f55d 100644 --- a/test/test_linux_python.py +++ b/test/test_linux_python.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import platform import subprocess -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - def test_python_exist(tmp_path: Path, capfd: pytest.CaptureFixture[str]) -> None: if utils.get_platform() != "linux": diff --git a/test/test_macos_archs.py b/test/test_macos_archs.py index ae00a51a6..b5274bc69 100644 --- a/test/test_macos_archs.py +++ b/test/test_macos_archs.py @@ -1,15 +1,10 @@ -from __future__ import annotations - import platform -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - basic_project = test_projects.new_c_project() basic_project.files["tests/test_suite.py"] = r""" import platform diff --git a/test/test_manylinuxXXXX_only.py b/test/test_manylinuxXXXX_only.py index e58c36461..2fbb4e3f5 100644 --- a/test/test_manylinuxXXXX_only.py +++ b/test/test_manylinuxXXXX_only.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import platform import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - # TODO: specify these at runtime according to manylinux_image project_with_manylinux_symbols = test_projects.new_c_project( spam_c_top_level_add=textwrap.dedent( diff --git a/test/test_meson_python.py b/test/test_meson_python.py index 62dd42406..5d507be69 100644 --- a/test/test_meson_python.py +++ b/test/test_meson_python.py @@ -1,14 +1,9 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING +from pathlib import Path import packaging.utils from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - meson_project = test_projects.new_meson_project() diff --git a/test/test_musllinux_X_Y_only.py b/test/test_musllinux_X_Y_only.py index ed3b67785..2a3f70af2 100644 --- a/test/test_musllinux_X_Y_only.py +++ b/test/test_musllinux_X_Y_only.py @@ -1,15 +1,10 @@ -from __future__ import annotations - import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_manylinux_symbols = test_projects.new_c_project( spam_c_top_level_add=textwrap.dedent( r""" diff --git a/test/test_pep518.py b/test/test_pep518.py index a5b24c918..4bc1fa6bf 100644 --- a/test/test_pep518.py +++ b/test/test_pep518.py @@ -1,14 +1,8 @@ -from __future__ import annotations - import textwrap from pathlib import Path -from typing import TYPE_CHECKING from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - basic_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( """ diff --git a/test/test_projects/base.py b/test/test_projects/base.py index e56f07881..dd8f2ce21 100644 --- a/test/test_projects/base.py +++ b/test/test_projects/base.py @@ -1,12 +1,8 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING, Any, Self +from pathlib import Path +from typing import Any, Self import jinja2 -if TYPE_CHECKING: - from pathlib import Path - FilesDict = dict[str, str | jinja2.Template] TemplateContext = dict[str, Any] diff --git a/test/test_pure_wheel.py b/test/test_pure_wheel.py index 6b0752e2a..dc7c0995d 100644 --- a/test/test_pure_wheel.py +++ b/test/test_pure_wheel.py @@ -1,8 +1,5 @@ -from __future__ import annotations - import subprocess from pathlib import Path -from typing import TYPE_CHECKING import pytest @@ -10,9 +7,6 @@ from . import utils -if TYPE_CHECKING: - from pathlib import Path - pure_python_project = test_projects.TestProject() pure_python_project.files["setup.py"] = """ from setuptools import Extension, setup diff --git a/test/test_pyodide.py b/test/test_pyodide.py index 3e90d6285..96873661d 100644 --- a/test/test_pyodide.py +++ b/test/test_pyodide.py @@ -1,11 +1,9 @@ -from __future__ import annotations - import contextlib import os import subprocess import sys import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest @@ -13,9 +11,6 @@ from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - pytestmark = pytest.mark.pyodide CIBW_PLATFORM = os.environ.get("CIBW_PLATFORM", "pyodide") diff --git a/test/test_ssl.py b/test/test_ssl.py index 8465a9d62..c43d18fbe 100644 --- a/test/test_ssl.py +++ b/test/test_ssl.py @@ -1,15 +1,10 @@ -from __future__ import annotations - import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_ssl_tests = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" diff --git a/test/test_subdir_package.py b/test/test_subdir_package.py index 656671195..e842b2d52 100644 --- a/test/test_subdir_package.py +++ b/test/test_subdir_package.py @@ -1,17 +1,12 @@ -from __future__ import annotations - from pathlib import Path -from typing import TYPE_CHECKING import jinja2 +import pytest from . import utils from .test_projects import TestProject from .test_projects.c import SPAM_C_TEMPLATE -if TYPE_CHECKING: - import pytest - subdir_package_project = TestProject() subdir_package_project.files["src/spam/spam.c"] = jinja2.Template(SPAM_C_TEMPLATE) diff --git a/test/test_testing.py b/test/test_testing.py index 118f3b0dd..39e6cd3fd 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -1,17 +1,12 @@ -from __future__ import annotations - import inspect import subprocess import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - project_with_a_test = test_projects.new_c_project( setup_cfg_add=textwrap.dedent( r""" diff --git a/test/test_troubleshooting.py b/test/test_troubleshooting.py index f12f55ea8..4c4680245 100644 --- a/test/test_troubleshooting.py +++ b/test/test_troubleshooting.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import subprocess -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import utils from .test_projects import TestProject, new_c_project -if TYPE_CHECKING: - from pathlib import Path - SO_FILE_WARNING = "NOTE: Shared object (.so) files found in this project." diff --git a/test/test_wheel_tag.py b/test/test_wheel_tag.py index 4f53f1a6b..2d9859248 100644 --- a/test/test_wheel_tag.py +++ b/test/test_wheel_tag.py @@ -1,14 +1,9 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING +from pathlib import Path import pytest from . import test_projects, utils -if TYPE_CHECKING: - from pathlib import Path - basic_project = test_projects.new_c_project() diff --git a/test/utils.py b/test/utils.py index 1d9502191..d451f7509 100644 --- a/test/utils.py +++ b/test/utils.py @@ -4,15 +4,14 @@ This file is added to the PYTHONPATH in the test runner at bin/run_test.py. """ -from __future__ import annotations - import os import platform as pm import subprocess import sys +from collections.abc import Generator, Mapping, Sequence from pathlib import Path from tempfile import TemporaryDirectory -from typing import TYPE_CHECKING, Final +from typing import Final import pytest @@ -21,9 +20,6 @@ from cibuildwheel.selector import EnableGroup from cibuildwheel.util.file import CIBW_CACHE_PATH -if TYPE_CHECKING: - from collections.abc import Generator, Mapping, Sequence - EMULATED_ARCHS: Final[list[str]] = sorted( arch.value for arch in (Architecture.all_archs("linux") - Architecture.auto_archs("linux")) ) diff --git a/unit_test/architecture_test.py b/unit_test/architecture_test.py index 907e4f063..f9112f6c8 100644 --- a/unit_test/architecture_test.py +++ b/unit_test/architecture_test.py @@ -1,17 +1,12 @@ -from __future__ import annotations - import platform as platform_module import shutil import sys -from typing import TYPE_CHECKING import pytest import cibuildwheel.architecture from cibuildwheel.architecture import Architecture, arch_synonym - -if TYPE_CHECKING: - from cibuildwheel.typing import PlatformName +from cibuildwheel.typing import PlatformName @pytest.fixture( diff --git a/unit_test/audit_test.py b/unit_test/audit_test.py index 833cf1d2a..49495d0ce 100644 --- a/unit_test/audit_test.py +++ b/unit_test/audit_test.py @@ -1,8 +1,6 @@ -from __future__ import annotations - +import contextlib import subprocess from pathlib import Path -from typing import TYPE_CHECKING from unittest.mock import Mock, patch import pytest @@ -10,9 +8,6 @@ from cibuildwheel import errors from cibuildwheel.audit import needs_audit, run_audit -if TYPE_CHECKING: - import contextlib - def mock_virtualenv() -> contextlib.AbstractContextManager[Mock]: return patch( diff --git a/unit_test/download_test.py b/unit_test/download_test.py index 8e42b62e0..68c7d9262 100644 --- a/unit_test/download_test.py +++ b/unit_test/download_test.py @@ -1,16 +1,11 @@ -from __future__ import annotations - import ssl -from typing import TYPE_CHECKING +from pathlib import Path import certifi import pytest from cibuildwheel.util.file import download -if TYPE_CHECKING: - from pathlib import Path - DOWNLOAD_URL = "https://cdn.jsdelivr.net/gh/pypa/cibuildwheel@v1.6.3/requirements-dev.txt" diff --git a/unit_test/get_platform_test.py b/unit_test/get_platform_test.py index efd1352d2..1cd7975e0 100644 --- a/unit_test/get_platform_test.py +++ b/unit_test/get_platform_test.py @@ -1,8 +1,7 @@ -from __future__ import annotations - import contextlib import sys -from typing import TYPE_CHECKING +from collections.abc import Generator +from pathlib import Path import pytest import setuptools._distutils.util @@ -11,9 +10,7 @@ from cibuildwheel.errors import FatalError from cibuildwheel.platforms.windows import PythonConfiguration, setup_setuptools_cross_compile -if TYPE_CHECKING: - from collections.abc import Generator - from pathlib import Path +TYPE_CHECKING = False # 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: diff --git a/unit_test/linux_build_steps_test.py b/unit_test/linux_build_steps_test.py index 16101d475..237ab1713 100644 --- a/unit_test/linux_build_steps_test.py +++ b/unit_test/linux_build_steps_test.py @@ -1,18 +1,13 @@ -from __future__ import annotations - import textwrap +from pathlib import Path from pprint import pprint -from typing import TYPE_CHECKING + +import pytest import cibuildwheel.platforms.linux from cibuildwheel.oci_container import OCIContainerEngineConfig from cibuildwheel.options import CommandLineArguments, Options -if TYPE_CHECKING: - from pathlib import Path - - import pytest - def test_linux_container_split(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: """ diff --git a/unit_test/main_commands_test.py b/unit_test/main_commands_test.py index 6eb52ff40..4383fe875 100644 --- a/unit_test/main_commands_test.py +++ b/unit_test/main_commands_test.py @@ -1,18 +1,13 @@ -from __future__ import annotations - import errno import shutil import sys -from typing import TYPE_CHECKING +from pathlib import Path import pytest import cibuildwheel.__main__ as main_module from cibuildwheel.__main__ import main -if TYPE_CHECKING: - from pathlib import Path - def test_clean_cache_when_cache_exists( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pytest.CaptureFixture[str] diff --git a/unit_test/main_tests/conftest.py b/unit_test/main_tests/conftest.py index e20aaed37..df683c67d 100644 --- a/unit_test/main_tests/conftest.py +++ b/unit_test/main_tests/conftest.py @@ -1,11 +1,10 @@ -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 TYPE_CHECKING, Any +from typing import Any import pytest @@ -14,9 +13,6 @@ from cibuildwheel.platforms import android, ios, linux, macos, pyodide, windows from cibuildwheel.util import file -if TYPE_CHECKING: - from collections.abc import Generator, Iterator - class ArgsInterceptor: def __init__(self) -> None: diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index 21f2e2b00..8e524f77a 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -2,9 +2,9 @@ import sys import tomllib +from collections.abc import Mapping from fnmatch import fnmatch from pathlib import Path -from typing import TYPE_CHECKING import pytest @@ -16,9 +16,8 @@ from cibuildwheel.util import resources 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 diff --git a/unit_test/main_tests/main_platform_test.py b/unit_test/main_tests/main_platform_test.py index fce33b339..51097d0e6 100644 --- a/unit_test/main_tests/main_platform_test.py +++ b/unit_test/main_tests/main_platform_test.py @@ -1,20 +1,14 @@ -from __future__ import annotations - import sys -from typing import TYPE_CHECKING 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 - -if TYPE_CHECKING: - from cibuildwheel.typing import PlatformName - - from .conftest import ArgsInterceptor +from .conftest import ArgsInterceptor @pytest.mark.parametrize("option_value", [None, "auto", ""]) diff --git a/unit_test/main_tests/main_requires_python_test.py b/unit_test/main_tests/main_requires_python_test.py index 4e1e82ce0..c79688d0d 100644 --- a/unit_test/main_tests/main_requires_python_test.py +++ b/unit_test/main_tests/main_requires_python_test.py @@ -1,18 +1,13 @@ -from __future__ import annotations - import sys import textwrap -from typing import TYPE_CHECKING +from pathlib import Path import pytest from packaging.specifiers import SpecifierSet from cibuildwheel.__main__ import main -if TYPE_CHECKING: - from pathlib import Path - - from .conftest import ArgsInterceptor +from .conftest import ArgsInterceptor @pytest.fixture(autouse=True) diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index 90fe39e14..7a9fa2364 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import contextlib import json import os @@ -9,9 +7,9 @@ import sys import textwrap import time +from collections.abc import Iterator from contextlib import nullcontext from pathlib import Path, PurePath, PurePosixPath -from typing import TYPE_CHECKING import pytest import tomli_w @@ -27,9 +25,6 @@ _check_engine_version, ) -if TYPE_CHECKING: - from collections.abc import Iterator - # Test utilities # for these tests we use manylinux2014 images, because they're available on diff --git a/unit_test/options_test.py b/unit_test/options_test.py index a6f13535c..4beb9c2da 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -1,11 +1,10 @@ -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 TYPE_CHECKING, Literal +from typing import Literal import pytest @@ -26,9 +25,6 @@ from cibuildwheel.util import resources from cibuildwheel.util.packaging import DependencyConstraints -if TYPE_CHECKING: - from collections.abc import Sequence - PYPROJECT_1 = """ [tool.cibuildwheel] build = ["cp38-*", "cp313-*"] diff --git a/unit_test/options_toml_test.py b/unit_test/options_toml_test.py index a65143433..0689be824 100644 --- a/unit_test/options_toml_test.py +++ b/unit_test/options_toml_test.py @@ -1,7 +1,6 @@ -from __future__ import annotations - import shlex -from typing import TYPE_CHECKING, Any, cast +from pathlib import Path +from typing import Any, cast import pytest @@ -14,11 +13,7 @@ ShlexTableFormat, _resolve_cascade, ) - -if TYPE_CHECKING: - from pathlib import Path - - from cibuildwheel.typing import PlatformName +from cibuildwheel.typing import PlatformName PYPROJECT_1 = """ [tool.cibuildwheel] diff --git a/unit_test/projectfiles_test.py b/unit_test/projectfiles_test.py index ba25ae72c..3e4068df7 100644 --- a/unit_test/projectfiles_test.py +++ b/unit_test/projectfiles_test.py @@ -1,8 +1,6 @@ -from __future__ import annotations - import tomllib +from pathlib import Path from textwrap import dedent -from typing import TYPE_CHECKING import pytest @@ -12,9 +10,6 @@ setup_py_python_requires, ) -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: