chore: use if TYPE_CHECKING: blocks (#2866)

This commit is contained in:
Matthieu Darbois
2026-05-27 18:20:08 -04:00
committed by GitHub
parent 2380f52783
commit e3e7cc9e07
79 changed files with 566 additions and 168 deletions
+6 -1
View File
@@ -1,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 cibuildwheel.venv import find_uv
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(
+6 -1
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import textwrap
from pathlib import Path
import packaging.utils
import pytest
@@ -9,6 +10,10 @@ from cibuildwheel.selector import EnableGroup
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(
"""
+6 -1
View File
@@ -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"]
+8 -3
View File
@@ -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"]
+6 -1
View File
@@ -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"""
+6 -1
View File
@@ -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"
+5 -1
View File
@@ -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
+6 -1
View File
@@ -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",
+6 -1
View File
@@ -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"""
+5 -1
View File
@@ -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()
+6 -1
View File
@@ -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"""
+5 -1
View File
@@ -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"""
+6 -1
View File
@@ -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 test import test_projects
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
+6 -1
View File
@@ -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 cibuildwheel.util import resources
from . import test_projects, utils
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
VERSION_REGEX = r"([\w-]+)==([^;\s]+)"
CHECK_VERSIONS_SCRIPT = """\
+6 -1
View File
@@ -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"""
+6 -1
View File
@@ -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"""
+10 -5
View File
@@ -1,17 +1,22 @@
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 test.test_projects.base import TestProject
from . import test_projects, utils
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Mapping
import pytest
from test.test_projects.base import TestProject
# utilities
+6 -1
View File
@@ -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")
+6 -1
View File
@@ -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":
+6 -1
View File
@@ -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
+6 -1
View File
@@ -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(
+5 -1
View File
@@ -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()
+6 -1
View File
@@ -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"""
+6
View File
@@ -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(
"""
+6 -1
View File
@@ -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]
+6
View File
@@ -1,3 +1,5 @@
from __future__ import annotations
import subprocess
from pathlib import Path
@@ -7,6 +9,10 @@ from test import test_projects
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
+6 -1
View File
@@ -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 cibuildwheel.util.file import CIBW_CACHE_PATH
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")
+6 -1
View File
@@ -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"""
+6 -1
View File
@@ -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)
+6 -1
View File
@@ -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"""
+6 -1
View File
@@ -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."
+5 -1
View File
@@ -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()
+6 -1
View File
@@ -4,11 +4,12 @@ Utility functions used by the cibuildwheel tests.
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.ci import CIProvider, detect_ci_provider
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"))
)