Skip to content

Commit

Permalink
refactor: restore typing for non-backports
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Apr 19, 2023
1 parent d996af5 commit 31bd9c9
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 42 deletions.
9 changes: 2 additions & 7 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 0 additions & 26 deletions cibuildwheel/_compat/typing.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
...
3 changes: 2 additions & 1 deletion cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
3 changes: 2 additions & 1 deletion cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cibuildwheel/oci_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
3 changes: 2 additions & 1 deletion cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions cibuildwheel/typing.py
Original file line number Diff line number Diff line change
@@ -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:
...
3 changes: 2 additions & 1 deletion cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 31bd9c9

Please sign in to comment.