Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions bin/update_pythons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@
import copy
import difflib
import logging
import sys
from collections.abc import Mapping, MutableMapping
from pathlib import Path
from typing import Any, Union

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
from cibuildwheel.typing import Final, Literal, TypedDict

log = logging.getLogger("cibw")

Expand Down
10 changes: 2 additions & 8 deletions bin/update_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
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.typing import Final
from cibuildwheel._compat import tomllib
from cibuildwheel._compat.typing import Final

log = logging.getLogger("cibw")

Expand Down
10 changes: 3 additions & 7 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
import cibuildwheel.macos
import cibuildwheel.util
import cibuildwheel.windows
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,
assert_never,
)
from cibuildwheel.typing import PLATFORMS, GenericPythonConfiguration, PlatformName
from cibuildwheel.util import (
CIBW_CACHE_PATH,
BuildSelector,
Expand Down Expand Up @@ -244,7 +240,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(
Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/_compat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
10 changes: 10 additions & 0 deletions cibuildwheel/_compat/functools.py
Original file line number Diff line number Diff line change
@@ -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",)
10 changes: 10 additions & 0 deletions cibuildwheel/_compat/tomllib.py
Original file line number Diff line number Diff line change
@@ -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",)
24 changes: 24 additions & 0 deletions cibuildwheel/_compat/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

import sys

if sys.version_info < (3, 8):
from typing_extensions import Final, Literal, OrderedDict, Protocol, TypedDict
else:
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 # noqa: TID251

__all__ = (
"Final",
"Literal",
"Protocol",
"Protocol",
"TypedDict",
"OrderedDict",
"assert_never",
"NotRequired",
)
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 .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: 1 addition & 2 deletions cibuildwheel/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion cibuildwheel/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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, 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 .typing import PathOrStr
from .util import (
AlreadyBuiltWheelError,
BuildSelector,
Expand Down
4 changes: 2 additions & 2 deletions cibuildwheel/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
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, 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 .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 .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
9 changes: 3 additions & 6 deletions cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
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
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 .typing import PLATFORMS, PlatformName
from .util import (
MANYLINUX_ARCHS,
MUSLLINUX_ARCHS,
Expand Down
5 changes: 1 addition & 4 deletions cibuildwheel/projectfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 4 additions & 20 deletions cibuildwheel/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,21 @@

import os
import subprocess
import sys
from typing import TYPE_CHECKING, Union
import typing
from typing import Union

if sys.version_info < (3, 8):
from typing_extensions import Final, Literal, OrderedDict, Protocol, TypedDict
else:
from typing import Final, Literal, OrderedDict, Protocol, TypedDict

if sys.version_info < (3, 11):
from typing_extensions import NotRequired, assert_never
else:
from typing import NotRequired, assert_never
from ._compat.typing import Final, Literal, Protocol

__all__ = (
"Final",
"Literal",
"PLATFORMS",
"PathOrStr",
"PlatformName",
"Protocol",
"PLATFORMS",
"PopenBytes",
"Protocol",
"TypedDict",
"OrderedDict",
"assert_never",
"NotRequired",
)


if TYPE_CHECKING:
if typing.TYPE_CHECKING:
PopenBytes = subprocess.Popen[bytes]
PathOrStr = Union[str, os.PathLike[str]]
else:
Expand Down
17 changes: 4 additions & 13 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@

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
from packaging.utils import parse_wheel_filename
from packaging.version import Version
from platformdirs import user_cache_path

from cibuildwheel.typing import Final, Literal, PathOrStr, PlatformName
from ._compat import tomllib
from ._compat.functools import cached_property
from ._compat.typing import Final, Literal
from .typing import PathOrStr, PlatformName

__all__ = [
"resources_dir",
Expand Down Expand Up @@ -661,12 +658,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]:
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 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 .typing import PathOrStr
from .util import (
CIBW_CACHE_PATH,
AlreadyBuiltWheelError,
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -158,6 +158,15 @@ 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 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"]
8 changes: 1 addition & 7 deletions unit_test/build_ids_test.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading