Skip to content

Commit d996af5

Browse files
committed
fix: restore Python 3.7 support
Signed-off-by: Henry Schreiner <[email protected]>
1 parent e42f243 commit d996af5

18 files changed

+41
-28
lines changed

bin/update_pythons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from rich.logging import RichHandler
2525
from rich.syntax import Syntax
2626

27+
from cibuildwheel._compat.typing import Final, Literal, TypedDict
2728
from cibuildwheel.extra import dump_python_configurations
28-
from cibuildwheel.typing import Final, Literal, TypedDict
2929

3030
log = logging.getLogger("cibw")
3131

bin/update_virtualenv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from rich.logging import RichHandler
2222
from rich.syntax import Syntax
2323

24-
from cibuildwheel.typing import Final
24+
from cibuildwheel._compat.typing import Final
2525

2626
log = logging.getLogger("cibw")
2727

cibuildwheel/__main__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
import cibuildwheel.macos
1717
import cibuildwheel.util
1818
import cibuildwheel.windows
19-
from cibuildwheel.architecture import Architecture, allowed_architectures_check
20-
from cibuildwheel.logger import log
21-
from cibuildwheel.options import CommandLineArguments, Options, compute_options
22-
from cibuildwheel.typing import (
19+
from cibuildwheel._compat.typing import (
2320
PLATFORMS,
2421
GenericPythonConfiguration,
2522
PlatformName,
23+
Protocol,
2624
assert_never,
2725
)
26+
from cibuildwheel.architecture import Architecture, allowed_architectures_check
27+
from cibuildwheel.logger import log
28+
from cibuildwheel.options import CommandLineArguments, Options, compute_options
2829
from cibuildwheel.util import (
2930
CIBW_CACHE_PATH,
3031
BuildSelector,
@@ -244,7 +245,7 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
244245
return _compute_platform_ci()
245246

246247

247-
class PlatformModule(typing.Protocol):
248+
class PlatformModule(Protocol):
248249
# note that as per PEP544, the self argument is ignored when the protocol
249250
# is applied to a module
250251
def get_python_configurations(

cibuildwheel/_compat/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from __future__ import annotations

cibuildwheel/_compat/functools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
if sys.version_info >= (3, 8):
6+
from functools import cached_property
7+
else:
8+
from ._functools_cached_property_38 import cached_property
9+
10+
__all__ = ("cached_property",)

cibuildwheel/typing.py renamed to cibuildwheel/_compat/typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
if sys.version_info < (3, 8):
99
from typing_extensions import Final, Literal, OrderedDict, Protocol, TypedDict
1010
else:
11-
from typing import Final, Literal, OrderedDict, Protocol, TypedDict
11+
from typing import Final, Literal, OrderedDict, Protocol, TypedDict # noqa: TID251
1212

1313
if sys.version_info < (3, 11):
1414
from typing_extensions import NotRequired, assert_never
1515
else:
16-
from typing import NotRequired, assert_never
16+
from typing import NotRequired, assert_never # noqa: TID251
1717

1818
__all__ = (
1919
"Final",

cibuildwheel/architecture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections.abc import Set
88
from enum import Enum
99

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

1212
PRETTY_NAMES: Final = {"linux": "Linux", "macos": "macOS", "windows": "Windows"}
1313

cibuildwheel/environment.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import bashlex
88
import bashlex.errors
99

10-
from cibuildwheel.typing import Protocol
11-
1210
from . import bashlex_eval
11+
from ._compat.typing import Protocol
1312

1413

1514
class EnvironmentParseError(Exception):

cibuildwheel/extra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from collections.abc import Mapping, Sequence
88
from io import StringIO
99

10-
from .typing import Protocol
10+
from ._compat.typing import Protocol
1111

1212
__all__ = ("Printable", "dump_python_configurations")
1313

cibuildwheel/linux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from pathlib import Path, PurePath, PurePosixPath
99
from typing import Tuple
1010

11+
from ._compat.typing import OrderedDict, PathOrStr, assert_never
1112
from .architecture import Architecture
1213
from .logger import log
1314
from .oci_container import OCIContainer
1415
from .options import Options
15-
from .typing import OrderedDict, PathOrStr, assert_never
1616
from .util import (
1717
AlreadyBuiltWheelError,
1818
BuildSelector,

cibuildwheel/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import time
88
from typing import IO, AnyStr
99

10-
from cibuildwheel.typing import Final
11-
from cibuildwheel.util import CIProvider, detect_ci_provider
10+
from ._compat.typing import Final
11+
from .util import CIProvider, detect_ci_provider
1212

1313
DEFAULT_FOLD_PATTERN: Final = ("{name}", "")
1414
FOLD_PATTERNS: Final = {

cibuildwheel/macos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
from filelock import FileLock
1818

19+
from ._compat.typing import Literal, PathOrStr, assert_never
1920
from .architecture import Architecture
2021
from .environment import ParsedEnvironment
2122
from .logger import log
2223
from .options import Options
23-
from .typing import Literal, PathOrStr, assert_never
2424
from .util import (
2525
CIBW_CACHE_PATH,
2626
AlreadyBuiltWheelError,

cibuildwheel/oci_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from cibuildwheel.util import CIProvider, detect_ci_provider
1919

20-
from .typing import Literal, PathOrStr, PopenBytes
20+
from ._compat.typing import Literal, PathOrStr, PopenBytes
2121

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

cibuildwheel/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
from packaging.specifiers import SpecifierSet
2424

25+
from ._compat.typing import PLATFORMS, Literal, NotRequired, PlatformName, TypedDict
2526
from .architecture import Architecture
2627
from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment
2728
from .logger import log
2829
from .oci_container import ContainerEngine
2930
from .projectfiles import get_requires_python_str
30-
from .typing import PLATFORMS, Literal, NotRequired, PlatformName, TypedDict
3131
from .util import (
3232
MANYLINUX_ARCHS,
3333
MUSLLINUX_ARCHS,

cibuildwheel/util.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
from packaging.version import Version
3737
from platformdirs import user_cache_path
3838

39-
from cibuildwheel.typing import Final, Literal, PathOrStr, PlatformName
39+
from ._compat.functools import cached_property
40+
from ._compat.typing import Final, Literal, PathOrStr, PlatformName
4041

4142
__all__ = [
4243
"resources_dir",
@@ -661,12 +662,6 @@ def find_compatible_wheel(wheels: Sequence[T], identifier: str) -> T | None:
661662
return None
662663

663664

664-
if sys.version_info >= (3, 8):
665-
from functools import cached_property
666-
else:
667-
from .functools_cached_property_38 import cached_property
668-
669-
670665
# Can be replaced by contextlib.chdir in Python 3.11
671666
@contextlib.contextmanager
672667
def chdir(new_path: Path | str) -> Generator[None, None, None]:

cibuildwheel/windows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
from filelock import FileLock
1717
from packaging.version import Version
1818

19+
from ._compat.typing import PathOrStr, assert_never
1920
from .architecture import Architecture
2021
from .environment import ParsedEnvironment
2122
from .logger import log
2223
from .options import Options
23-
from .typing import PathOrStr, assert_never
2424
from .util import (
2525
CIBW_CACHE_PATH,
2626
AlreadyBuiltWheelError,

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ extend-ignore = [
149149
"PT007", # False positive (fixed upstream)
150150
]
151151
target-version = "py37"
152-
typing-modules = ["cibuildwheel.typing"]
152+
typing-modules = ["cibuildwheel._compat.typing"]
153153
flake8-unused-arguments.ignore-variadic-names = true
154154

155155
[tool.ruff.flake8-tidy-imports.banned-api]
@@ -158,6 +158,13 @@ flake8-unused-arguments.ignore-variadic-names = true
158158
"typing.Iterator".msg = "Use collections.abc.Iterator instead."
159159
"typing.Sequence".msg = "Use collections.abc.Sequence instead."
160160
"typing.Set".msg = "Use collections.abc.Set instead."
161+
"typing.Protocol".msg = "Use cibuildwheel._compat.typing.Protocol instead."
162+
"typing.Final".msg = "Use cibuildwheel._compat.typing.Final instead."
163+
"typing.Literal".msg = "Use cibuildwheel._compat.typing.Literal instead."
164+
"typing.OrderedDict".msg = "Use cibuildwheel._compat.typing.OrderedDict instead."
165+
"typing.TypedDict".msg = "Use cibuildwheel._compat.typing.TypedDict instead."
166+
"typing.NotRequired".msg = "Use cibuildwheel._compat.typing.NotRequired instead."
167+
"typing.assert_never".msg = "Use cibuildwhee._compat.typing.assert_never instead."
161168

162169
[tool.ruff.per-file-ignores]
163170
"unit_test/*" = ["PLC1901"]

0 commit comments

Comments
 (0)