Skip to content

Commit 31bd9c9

Browse files
committed
refactor: restore typing for non-backports
Signed-off-by: Henry Schreiner <[email protected]>
1 parent d996af5 commit 31bd9c9

File tree

10 files changed

+51
-42
lines changed

10 files changed

+51
-42
lines changed

cibuildwheel/__main__.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616
import cibuildwheel.macos
1717
import cibuildwheel.util
1818
import cibuildwheel.windows
19-
from cibuildwheel._compat.typing import (
20-
PLATFORMS,
21-
GenericPythonConfiguration,
22-
PlatformName,
23-
Protocol,
24-
assert_never,
25-
)
19+
from cibuildwheel._compat.typing import Protocol, assert_never
2620
from cibuildwheel.architecture import Architecture, allowed_architectures_check
2721
from cibuildwheel.logger import log
2822
from cibuildwheel.options import CommandLineArguments, Options, compute_options
23+
from cibuildwheel.typing import PLATFORMS, GenericPythonConfiguration, PlatformName
2924
from cibuildwheel.util import (
3025
CIBW_CACHE_PATH,
3126
BuildSelector,

cibuildwheel/_compat/typing.py

-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__ import annotations
22

3-
import os
4-
import subprocess
53
import sys
6-
from typing import TYPE_CHECKING, Union
74

85
if sys.version_info < (3, 8):
96
from typing_extensions import Final, Literal, OrderedDict, Protocol, TypedDict
@@ -18,33 +15,10 @@
1815
__all__ = (
1916
"Final",
2017
"Literal",
21-
"PLATFORMS",
22-
"PathOrStr",
23-
"PlatformName",
2418
"Protocol",
25-
"PLATFORMS",
26-
"PopenBytes",
2719
"Protocol",
2820
"TypedDict",
2921
"OrderedDict",
3022
"assert_never",
3123
"NotRequired",
3224
)
33-
34-
35-
if TYPE_CHECKING:
36-
PopenBytes = subprocess.Popen[bytes]
37-
PathOrStr = Union[str, os.PathLike[str]]
38-
else:
39-
PopenBytes = subprocess.Popen
40-
PathOrStr = Union[str, "os.PathLike[str]"]
41-
42-
43-
PlatformName = Literal["linux", "macos", "windows"]
44-
PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"}
45-
46-
47-
class GenericPythonConfiguration(Protocol):
48-
@property
49-
def identifier(self) -> str:
50-
...

cibuildwheel/architecture.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from collections.abc import Set
88
from enum import Enum
99

10-
from ._compat.typing import Final, Literal, PlatformName, assert_never
10+
from ._compat.typing import Final, Literal, assert_never
11+
from .typing import PlatformName
1112

1213
PRETTY_NAMES: Final = {"linux": "Linux", "macos": "macOS", "windows": "Windows"}
1314

cibuildwheel/linux.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
from pathlib import Path, PurePath, PurePosixPath
99
from typing import Tuple
1010

11-
from ._compat.typing import OrderedDict, PathOrStr, assert_never
11+
from ._compat.typing import OrderedDict, assert_never
1212
from .architecture import Architecture
1313
from .logger import log
1414
from .oci_container import OCIContainer
1515
from .options import Options
16+
from .typing import PathOrStr
1617
from .util import (
1718
AlreadyBuiltWheelError,
1819
BuildSelector,

cibuildwheel/macos.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
from filelock import FileLock
1818

19-
from ._compat.typing import Literal, PathOrStr, assert_never
19+
from ._compat.typing import Literal, assert_never
2020
from .architecture import Architecture
2121
from .environment import ParsedEnvironment
2222
from .logger import log
2323
from .options import Options
24+
from .typing import PathOrStr
2425
from .util import (
2526
CIBW_CACHE_PATH,
2627
AlreadyBuiltWheelError,

cibuildwheel/oci_container.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from types import TracebackType
1616
from typing import IO, Dict
1717

18-
from cibuildwheel.util import CIProvider, detect_ci_provider
19-
20-
from ._compat.typing import Literal, PathOrStr, PopenBytes
18+
from ._compat.typing import Literal
19+
from .typing import PathOrStr, PopenBytes
20+
from .util import CIProvider, detect_ci_provider
2121

2222
ContainerEngine = Literal["docker", "podman"]
2323

cibuildwheel/options.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222

2323
from packaging.specifiers import SpecifierSet
2424

25-
from ._compat.typing import PLATFORMS, Literal, NotRequired, PlatformName, TypedDict
25+
from ._compat.typing import Literal, NotRequired, TypedDict
2626
from .architecture import Architecture
2727
from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment
2828
from .logger import log
2929
from .oci_container import ContainerEngine
3030
from .projectfiles import get_requires_python_str
31+
from .typing import PLATFORMS, PlatformName
3132
from .util import (
3233
MANYLINUX_ARCHS,
3334
MUSLLINUX_ARCHS,

cibuildwheel/typing.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import subprocess
5+
import typing
6+
from typing import Union
7+
8+
from ._compat.typing import Final, Literal, Protocol
9+
10+
__all__ = (
11+
"PLATFORMS",
12+
"PathOrStr",
13+
"PlatformName",
14+
"PLATFORMS",
15+
"PopenBytes",
16+
)
17+
18+
19+
if typing.TYPE_CHECKING:
20+
PopenBytes = subprocess.Popen[bytes]
21+
PathOrStr = Union[str, os.PathLike[str]]
22+
else:
23+
PopenBytes = subprocess.Popen
24+
PathOrStr = Union[str, "os.PathLike[str]"]
25+
26+
27+
PlatformName = Literal["linux", "macos", "windows"]
28+
PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"}
29+
30+
31+
class GenericPythonConfiguration(Protocol):
32+
@property
33+
def identifier(self) -> str:
34+
...

cibuildwheel/util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
from platformdirs import user_cache_path
3838

3939
from ._compat.functools import cached_property
40-
from ._compat.typing import Final, Literal, PathOrStr, PlatformName
40+
from ._compat.typing import Final, Literal
41+
from .typing import PathOrStr, PlatformName
4142

4243
__all__ = [
4344
"resources_dir",

cibuildwheel/windows.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
from filelock import FileLock
1717
from packaging.version import Version
1818

19-
from ._compat.typing import PathOrStr, assert_never
19+
from ._compat.typing import assert_never
2020
from .architecture import Architecture
2121
from .environment import ParsedEnvironment
2222
from .logger import log
2323
from .options import Options
24+
from .typing import PathOrStr
2425
from .util import (
2526
CIBW_CACHE_PATH,
2627
AlreadyBuiltWheelError,

0 commit comments

Comments
 (0)