From e42f243b523a93352f0686ba2f4a62b7bf5f7d34 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 18 Apr 2023 21:42:16 -0400 Subject: [PATCH 1/4] ci: add Python 3.7 Signed-off-by: Henry Schreiner --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 36ed2511b..aa07602eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,9 @@ jobs: matrix: os: [ubuntu-20.04, windows-latest, macos-11] python_version: ['3.11'] + include: + - os: ubuntu-22.04 + python_version: '3.7' timeout-minutes: 180 steps: - uses: actions/checkout@v3 From d996af554ae21435028e538e417e403e8db7433e Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 18 Apr 2023 22:02:47 -0400 Subject: [PATCH 2/4] fix: restore Python 3.7 support Signed-off-by: Henry Schreiner --- bin/update_pythons.py | 2 +- bin/update_virtualenv.py | 2 +- cibuildwheel/__main__.py | 11 ++++++----- cibuildwheel/_compat/__init__.py | 1 + .../_functools_cached_property_38.py} | 0 cibuildwheel/_compat/functools.py | 10 ++++++++++ cibuildwheel/{ => _compat}/typing.py | 4 ++-- cibuildwheel/architecture.py | 2 +- cibuildwheel/environment.py | 3 +-- cibuildwheel/extra.py | 2 +- cibuildwheel/linux.py | 2 +- cibuildwheel/logger.py | 4 ++-- cibuildwheel/macos.py | 2 +- cibuildwheel/oci_container.py | 2 +- cibuildwheel/options.py | 2 +- cibuildwheel/util.py | 9 ++------- cibuildwheel/windows.py | 2 +- pyproject.toml | 9 ++++++++- 18 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 cibuildwheel/_compat/__init__.py rename cibuildwheel/{functools_cached_property_38.py => _compat/_functools_cached_property_38.py} (100%) create mode 100644 cibuildwheel/_compat/functools.py rename cibuildwheel/{ => _compat}/typing.py (92%) diff --git a/bin/update_pythons.py b/bin/update_pythons.py index 35f6a76ed..8649f765e 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -24,8 +24,8 @@ from rich.logging import RichHandler from rich.syntax import Syntax +from cibuildwheel._compat.typing import Final, Literal, TypedDict from cibuildwheel.extra import dump_python_configurations -from cibuildwheel.typing import Final, Literal, TypedDict log = logging.getLogger("cibw") diff --git a/bin/update_virtualenv.py b/bin/update_virtualenv.py index d7c7dc8ae..7e22d3834 100755 --- a/bin/update_virtualenv.py +++ b/bin/update_virtualenv.py @@ -21,7 +21,7 @@ from rich.logging import RichHandler from rich.syntax import Syntax -from cibuildwheel.typing import Final +from cibuildwheel._compat.typing import Final log = logging.getLogger("cibw") diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 9dfba1512..c6b02becc 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -16,15 +16,16 @@ import cibuildwheel.macos import cibuildwheel.util import cibuildwheel.windows -from cibuildwheel.architecture import Architecture, allowed_architectures_check -from cibuildwheel.logger import log -from cibuildwheel.options import CommandLineArguments, Options, compute_options -from cibuildwheel.typing import ( +from cibuildwheel._compat.typing import ( PLATFORMS, GenericPythonConfiguration, PlatformName, + Protocol, assert_never, ) +from cibuildwheel.architecture import Architecture, allowed_architectures_check +from cibuildwheel.logger import log +from cibuildwheel.options import CommandLineArguments, Options, compute_options from cibuildwheel.util import ( CIBW_CACHE_PATH, BuildSelector, @@ -244,7 +245,7 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName: return _compute_platform_ci() -class PlatformModule(typing.Protocol): +class PlatformModule(Protocol): # note that as per PEP544, the self argument is ignored when the protocol # is applied to a module def get_python_configurations( diff --git a/cibuildwheel/_compat/__init__.py b/cibuildwheel/_compat/__init__.py new file mode 100644 index 000000000..9d48db4f9 --- /dev/null +++ b/cibuildwheel/_compat/__init__.py @@ -0,0 +1 @@ +from __future__ import annotations diff --git a/cibuildwheel/functools_cached_property_38.py b/cibuildwheel/_compat/_functools_cached_property_38.py similarity index 100% rename from cibuildwheel/functools_cached_property_38.py rename to cibuildwheel/_compat/_functools_cached_property_38.py diff --git a/cibuildwheel/_compat/functools.py b/cibuildwheel/_compat/functools.py new file mode 100644 index 000000000..8fe86a3e4 --- /dev/null +++ b/cibuildwheel/_compat/functools.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +import sys + +if sys.version_info >= (3, 8): + from functools import cached_property +else: + from ._functools_cached_property_38 import cached_property + +__all__ = ("cached_property",) diff --git a/cibuildwheel/typing.py b/cibuildwheel/_compat/typing.py similarity index 92% rename from cibuildwheel/typing.py rename to cibuildwheel/_compat/typing.py index 9374401cb..01475bbb3 100644 --- a/cibuildwheel/typing.py +++ b/cibuildwheel/_compat/typing.py @@ -8,12 +8,12 @@ if sys.version_info < (3, 8): from typing_extensions import Final, Literal, OrderedDict, Protocol, TypedDict else: - from typing import Final, Literal, OrderedDict, Protocol, TypedDict + from typing import Final, Literal, OrderedDict, Protocol, TypedDict # noqa: TID251 if sys.version_info < (3, 11): from typing_extensions import NotRequired, assert_never else: - from typing import NotRequired, assert_never + from typing import NotRequired, assert_never # noqa: TID251 __all__ = ( "Final", diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 8c4b22939..ec5116f2f 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -7,7 +7,7 @@ from collections.abc import Set from enum import Enum -from .typing import Final, Literal, PlatformName, assert_never +from ._compat.typing import Final, Literal, PlatformName, assert_never PRETTY_NAMES: Final = {"linux": "Linux", "macos": "macOS", "windows": "Windows"} diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index 2a7b99a2a..3117b54ed 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -7,9 +7,8 @@ import bashlex import bashlex.errors -from cibuildwheel.typing import Protocol - from . import bashlex_eval +from ._compat.typing import Protocol class EnvironmentParseError(Exception): diff --git a/cibuildwheel/extra.py b/cibuildwheel/extra.py index 03e3ce6f0..5ac9ea1ff 100644 --- a/cibuildwheel/extra.py +++ b/cibuildwheel/extra.py @@ -7,7 +7,7 @@ from collections.abc import Mapping, Sequence from io import StringIO -from .typing import Protocol +from ._compat.typing import Protocol __all__ = ("Printable", "dump_python_configurations") diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 4f019ac34..18ab19544 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -8,11 +8,11 @@ from pathlib import Path, PurePath, PurePosixPath from typing import Tuple +from ._compat.typing import OrderedDict, PathOrStr, assert_never from .architecture import Architecture from .logger import log from .oci_container import OCIContainer from .options import Options -from .typing import OrderedDict, PathOrStr, assert_never from .util import ( AlreadyBuiltWheelError, BuildSelector, diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index 014f3b00d..bc63a3aaf 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -7,8 +7,8 @@ import time from typing import IO, AnyStr -from cibuildwheel.typing import Final -from cibuildwheel.util import CIProvider, detect_ci_provider +from ._compat.typing import Final +from .util import CIProvider, detect_ci_provider DEFAULT_FOLD_PATTERN: Final = ("{name}", "") FOLD_PATTERNS: Final = { diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 75614449b..10f26d0fe 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -16,11 +16,11 @@ from filelock import FileLock +from ._compat.typing import Literal, PathOrStr, assert_never from .architecture import Architecture from .environment import ParsedEnvironment from .logger import log from .options import Options -from .typing import Literal, PathOrStr, assert_never from .util import ( CIBW_CACHE_PATH, AlreadyBuiltWheelError, diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index aa54eefbf..4d76c5c3d 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -17,7 +17,7 @@ from cibuildwheel.util import CIProvider, detect_ci_provider -from .typing import Literal, PathOrStr, PopenBytes +from ._compat.typing import Literal, PathOrStr, PopenBytes ContainerEngine = Literal["docker", "podman"] diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index d28e76214..7214bea04 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -22,12 +22,12 @@ from packaging.specifiers import SpecifierSet +from ._compat.typing import PLATFORMS, Literal, NotRequired, PlatformName, TypedDict from .architecture import Architecture from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment from .logger import log from .oci_container import ContainerEngine from .projectfiles import get_requires_python_str -from .typing import PLATFORMS, Literal, NotRequired, PlatformName, TypedDict from .util import ( MANYLINUX_ARCHS, MUSLLINUX_ARCHS, diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 2ba4fe6a1..0b5ae24ce 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -36,7 +36,8 @@ from packaging.version import Version from platformdirs import user_cache_path -from cibuildwheel.typing import Final, Literal, PathOrStr, PlatformName +from ._compat.functools import cached_property +from ._compat.typing import Final, Literal, PathOrStr, PlatformName __all__ = [ "resources_dir", @@ -661,12 +662,6 @@ def find_compatible_wheel(wheels: Sequence[T], identifier: str) -> T | None: return None -if sys.version_info >= (3, 8): - from functools import cached_property -else: - from .functools_cached_property_38 import cached_property - - # Can be replaced by contextlib.chdir in Python 3.11 @contextlib.contextmanager def chdir(new_path: Path | str) -> Generator[None, None, None]: diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index caee9ce69..eba342b38 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -16,11 +16,11 @@ from filelock import FileLock from packaging.version import Version +from ._compat.typing import PathOrStr, assert_never from .architecture import Architecture from .environment import ParsedEnvironment from .logger import log from .options import Options -from .typing import PathOrStr, assert_never from .util import ( CIBW_CACHE_PATH, AlreadyBuiltWheelError, diff --git a/pyproject.toml b/pyproject.toml index 570772db4..29e9c2312 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -149,7 +149,7 @@ extend-ignore = [ "PT007", # False positive (fixed upstream) ] target-version = "py37" -typing-modules = ["cibuildwheel.typing"] +typing-modules = ["cibuildwheel._compat.typing"] flake8-unused-arguments.ignore-variadic-names = true [tool.ruff.flake8-tidy-imports.banned-api] @@ -158,6 +158,13 @@ flake8-unused-arguments.ignore-variadic-names = 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.Protocol".msg = "Use cibuildwheel._compat.typing.Protocol instead." +"typing.Final".msg = "Use cibuildwheel._compat.typing.Final instead." +"typing.Literal".msg = "Use cibuildwheel._compat.typing.Literal instead." +"typing.OrderedDict".msg = "Use cibuildwheel._compat.typing.OrderedDict instead." +"typing.TypedDict".msg = "Use cibuildwheel._compat.typing.TypedDict instead." +"typing.NotRequired".msg = "Use cibuildwheel._compat.typing.NotRequired instead." +"typing.assert_never".msg = "Use cibuildwhee._compat.typing.assert_never instead." [tool.ruff.per-file-ignores] "unit_test/*" = ["PLC1901"] From 31bd9c91743e09f5b48c4def38c255c14c00d1af Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 18 Apr 2023 23:05:34 -0400 Subject: [PATCH 3/4] refactor: restore typing for non-backports Signed-off-by: Henry Schreiner --- cibuildwheel/__main__.py | 9 ++------- cibuildwheel/_compat/typing.py | 26 -------------------------- cibuildwheel/architecture.py | 3 ++- cibuildwheel/linux.py | 3 ++- cibuildwheel/macos.py | 3 ++- cibuildwheel/oci_container.py | 6 +++--- cibuildwheel/options.py | 3 ++- cibuildwheel/typing.py | 34 ++++++++++++++++++++++++++++++++++ cibuildwheel/util.py | 3 ++- cibuildwheel/windows.py | 3 ++- 10 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 cibuildwheel/typing.py diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index c6b02becc..3682fad49 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -16,16 +16,11 @@ import cibuildwheel.macos import cibuildwheel.util import cibuildwheel.windows -from cibuildwheel._compat.typing import ( - PLATFORMS, - GenericPythonConfiguration, - PlatformName, - Protocol, - assert_never, -) +from cibuildwheel._compat.typing import Protocol, assert_never from cibuildwheel.architecture import Architecture, allowed_architectures_check from cibuildwheel.logger import log from cibuildwheel.options import CommandLineArguments, Options, compute_options +from cibuildwheel.typing import PLATFORMS, GenericPythonConfiguration, PlatformName from cibuildwheel.util import ( CIBW_CACHE_PATH, BuildSelector, diff --git a/cibuildwheel/_compat/typing.py b/cibuildwheel/_compat/typing.py index 01475bbb3..62495adf9 100644 --- a/cibuildwheel/_compat/typing.py +++ b/cibuildwheel/_compat/typing.py @@ -1,9 +1,6 @@ from __future__ import annotations -import os -import subprocess import sys -from typing import TYPE_CHECKING, Union if sys.version_info < (3, 8): from typing_extensions import Final, Literal, OrderedDict, Protocol, TypedDict @@ -18,33 +15,10 @@ __all__ = ( "Final", "Literal", - "PLATFORMS", - "PathOrStr", - "PlatformName", "Protocol", - "PLATFORMS", - "PopenBytes", "Protocol", "TypedDict", "OrderedDict", "assert_never", "NotRequired", ) - - -if TYPE_CHECKING: - PopenBytes = subprocess.Popen[bytes] - PathOrStr = Union[str, os.PathLike[str]] -else: - PopenBytes = subprocess.Popen - PathOrStr = Union[str, "os.PathLike[str]"] - - -PlatformName = Literal["linux", "macos", "windows"] -PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"} - - -class GenericPythonConfiguration(Protocol): - @property - def identifier(self) -> str: - ... diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index ec5116f2f..9d9af38b8 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -7,7 +7,8 @@ from collections.abc import Set from enum import Enum -from ._compat.typing import Final, Literal, PlatformName, assert_never +from ._compat.typing import Final, Literal, assert_never +from .typing import PlatformName PRETTY_NAMES: Final = {"linux": "Linux", "macos": "macOS", "windows": "Windows"} diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 18ab19544..6fd393dc5 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -8,11 +8,12 @@ from pathlib import Path, PurePath, PurePosixPath from typing import Tuple -from ._compat.typing import OrderedDict, PathOrStr, assert_never +from ._compat.typing import OrderedDict, assert_never from .architecture import Architecture from .logger import log from .oci_container import OCIContainer from .options import Options +from .typing import PathOrStr from .util import ( AlreadyBuiltWheelError, BuildSelector, diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 10f26d0fe..1c103629d 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -16,11 +16,12 @@ from filelock import FileLock -from ._compat.typing import Literal, PathOrStr, assert_never +from ._compat.typing import Literal, assert_never from .architecture import Architecture from .environment import ParsedEnvironment from .logger import log from .options import Options +from .typing import PathOrStr from .util import ( CIBW_CACHE_PATH, AlreadyBuiltWheelError, diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index 4d76c5c3d..b2f6fe4af 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -15,9 +15,9 @@ from types import TracebackType from typing import IO, Dict -from cibuildwheel.util import CIProvider, detect_ci_provider - -from ._compat.typing import Literal, PathOrStr, PopenBytes +from ._compat.typing import Literal +from .typing import PathOrStr, PopenBytes +from .util import CIProvider, detect_ci_provider ContainerEngine = Literal["docker", "podman"] diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index 7214bea04..d4c88222b 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -22,12 +22,13 @@ from packaging.specifiers import SpecifierSet -from ._compat.typing import PLATFORMS, Literal, NotRequired, PlatformName, TypedDict +from ._compat.typing import Literal, NotRequired, TypedDict from .architecture import Architecture from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment from .logger import log from .oci_container import ContainerEngine from .projectfiles import get_requires_python_str +from .typing import PLATFORMS, PlatformName from .util import ( MANYLINUX_ARCHS, MUSLLINUX_ARCHS, diff --git a/cibuildwheel/typing.py b/cibuildwheel/typing.py new file mode 100644 index 000000000..7abd9e3cf --- /dev/null +++ b/cibuildwheel/typing.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +import os +import subprocess +import typing +from typing import Union + +from ._compat.typing import Final, Literal, Protocol + +__all__ = ( + "PLATFORMS", + "PathOrStr", + "PlatformName", + "PLATFORMS", + "PopenBytes", +) + + +if typing.TYPE_CHECKING: + PopenBytes = subprocess.Popen[bytes] + PathOrStr = Union[str, os.PathLike[str]] +else: + PopenBytes = subprocess.Popen + PathOrStr = Union[str, "os.PathLike[str]"] + + +PlatformName = Literal["linux", "macos", "windows"] +PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"} + + +class GenericPythonConfiguration(Protocol): + @property + def identifier(self) -> str: + ... diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 0b5ae24ce..00771eb5b 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -37,7 +37,8 @@ from platformdirs import user_cache_path from ._compat.functools import cached_property -from ._compat.typing import Final, Literal, PathOrStr, PlatformName +from ._compat.typing import Final, Literal +from .typing import PathOrStr, PlatformName __all__ = [ "resources_dir", diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index eba342b38..d3e587868 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -16,11 +16,12 @@ from filelock import FileLock from packaging.version import Version -from ._compat.typing import PathOrStr, assert_never +from ._compat.typing import assert_never from .architecture import Architecture from .environment import ParsedEnvironment from .logger import log from .options import Options +from .typing import PathOrStr from .util import ( CIBW_CACHE_PATH, AlreadyBuiltWheelError, From aff6dd5adc49114f1ee49c82bcb386a142fc614a Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 18 Apr 2023 23:29:54 -0400 Subject: [PATCH 4/4] refactor: tomllib in _compat Signed-off-by: Henry Schreiner --- bin/update_pythons.py | 8 +------- bin/update_virtualenv.py | 8 +------- cibuildwheel/_compat/tomllib.py | 10 ++++++++++ cibuildwheel/options.py | 6 +----- cibuildwheel/projectfiles.py | 5 +---- cibuildwheel/util.py | 7 +------ pyproject.toml | 4 +++- unit_test/build_ids_test.py | 8 +------- unit_test/main_tests/main_options_test.py | 6 +----- 9 files changed, 20 insertions(+), 42 deletions(-) create mode 100644 cibuildwheel/_compat/tomllib.py diff --git a/bin/update_pythons.py b/bin/update_pythons.py index 8649f765e..e57a71735 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -5,7 +5,6 @@ import copy import difflib import logging -import sys from collections.abc import Mapping, MutableMapping from pathlib import Path from typing import Any, Union @@ -13,17 +12,12 @@ import click import requests import rich - -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - from packaging.specifiers import Specifier from packaging.version import Version from rich.logging import RichHandler from rich.syntax import Syntax +from cibuildwheel._compat import tomllib from cibuildwheel._compat.typing import Final, Literal, TypedDict from cibuildwheel.extra import dump_python_configurations diff --git a/bin/update_virtualenv.py b/bin/update_virtualenv.py index 7e22d3834..a00724063 100755 --- a/bin/update_virtualenv.py +++ b/bin/update_virtualenv.py @@ -5,22 +5,16 @@ import difflib import logging import subprocess -import sys from dataclasses import dataclass from pathlib import Path import click import rich - -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - from packaging.version import InvalidVersion, Version from rich.logging import RichHandler from rich.syntax import Syntax +from cibuildwheel._compat import tomllib from cibuildwheel._compat.typing import Final log = logging.getLogger("cibw") diff --git a/cibuildwheel/_compat/tomllib.py b/cibuildwheel/_compat/tomllib.py new file mode 100644 index 000000000..f3b30fe65 --- /dev/null +++ b/cibuildwheel/_compat/tomllib.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +import sys + +if sys.version_info >= (3, 11): + from tomllib import load # noqa: TID251 +else: + from tomli import load # noqa: TID251 + +__all__ = ("load",) diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index d4c88222b..736f13a73 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -15,13 +15,9 @@ from pathlib import Path from typing import Any, Dict, List, Union -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - from packaging.specifiers import SpecifierSet +from ._compat import tomllib from ._compat.typing import Literal, NotRequired, TypedDict from .architecture import Architecture from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment diff --git a/cibuildwheel/projectfiles.py b/cibuildwheel/projectfiles.py index 0b87415b6..95dc150d8 100644 --- a/cibuildwheel/projectfiles.py +++ b/cibuildwheel/projectfiles.py @@ -7,10 +7,7 @@ from pathlib import Path from typing import Any -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib +from ._compat import tomllib if sys.version_info < (3, 8): Constant = ast.Str diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 00771eb5b..8b5f9f620 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -23,12 +23,6 @@ import bracex import certifi - -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - from filelock import FileLock from packaging.requirements import InvalidRequirement, Requirement from packaging.specifiers import SpecifierSet @@ -36,6 +30,7 @@ from packaging.version import Version from platformdirs import user_cache_path +from ._compat import tomllib from ._compat.functools import cached_property from ._compat.typing import Final, Literal from .typing import PathOrStr, PlatformName diff --git a/pyproject.toml b/pyproject.toml index 29e9c2312..90420fcaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -164,7 +164,9 @@ flake8-unused-arguments.ignore-variadic-names = true "typing.OrderedDict".msg = "Use cibuildwheel._compat.typing.OrderedDict instead." "typing.TypedDict".msg = "Use cibuildwheel._compat.typing.TypedDict instead." "typing.NotRequired".msg = "Use cibuildwheel._compat.typing.NotRequired instead." -"typing.assert_never".msg = "Use cibuildwhee._compat.typing.assert_never instead." +"typing.assert_never".msg = "Use cibuildwheel._compat.typing.assert_never instead." +"tomllib".msg = "Use cibuildwheel._compat.tomllib instead." +"tomli".msg = "Use cibuildwheel._compat.tomllib instead." [tool.ruff.per-file-ignores] "unit_test/*" = ["PLC1901"] diff --git a/unit_test/build_ids_test.py b/unit_test/build_ids_test.py index 0f62ba408..a42af93de 100644 --- a/unit_test/build_ids_test.py +++ b/unit_test/build_ids_test.py @@ -1,14 +1,8 @@ from __future__ import annotations -import sys - -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - from packaging.version import Version +from cibuildwheel._compat import tomllib from cibuildwheel.extra import Printable, dump_python_configurations from cibuildwheel.util import resources_dir diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index 6cda8967b..8d2010ee3 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -6,12 +6,8 @@ import pytest -if sys.version_info >= (3, 11): - import tomllib -else: - import tomli as tomllib - from cibuildwheel.__main__ import main +from cibuildwheel._compat import tomllib from cibuildwheel.environment import ParsedEnvironment from cibuildwheel.options import BuildOptions, _get_pinned_container_images from cibuildwheel.util import BuildSelector, resources_dir, split_config_settings