From 31bd9c91743e09f5b48c4def38c255c14c00d1af Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 18 Apr 2023 23:05:34 -0400 Subject: [PATCH] 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,