chore: use if TYPE_CHECKING: blocks (#2866)
This commit is contained in:
+6
-1
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
"""
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = """\
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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
@@ -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
@@ -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")
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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(
|
||||
"""
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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"""
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"""
|
||||
|
||||
@@ -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."
|
||||
|
||||
|
||||
|
||||
@@ -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
@@ -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"))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user