chore: add structurally typed GenericPythonConfiguration (#1458)

* Add structually typed GenericPythonConfiguration

Use structural typing for the return value of get_python_configurations
so that we don't have to specify a union of all possible PythonConfiguration
types

* address henryiii's comments

* Use Set in more places
This commit is contained in:
Hood Chatham
2023-04-06 14:40:25 -04:00
committed by GitHub
parent bd5294b3f3
commit d018570bc4
5 changed files with 21 additions and 10 deletions
+9 -7
View File
@@ -7,6 +7,7 @@ import sys
import tarfile import tarfile
import textwrap import textwrap
import typing import typing
from collections.abc import Sequence, Set
from pathlib import Path from pathlib import Path
from tempfile import mkdtemp from tempfile import mkdtemp
@@ -18,7 +19,12 @@ import cibuildwheel.windows
from cibuildwheel.architecture import Architecture, allowed_architectures_check from cibuildwheel.architecture import Architecture, allowed_architectures_check
from cibuildwheel.logger import log from cibuildwheel.logger import log
from cibuildwheel.options import CommandLineArguments, Options, compute_options from cibuildwheel.options import CommandLineArguments, Options, compute_options
from cibuildwheel.typing import PLATFORMS, PlatformName, assert_never from cibuildwheel.typing import (
PLATFORMS,
GenericPythonConfiguration,
PlatformName,
assert_never,
)
from cibuildwheel.util import ( from cibuildwheel.util import (
CIBW_CACHE_PATH, CIBW_CACHE_PATH,
BuildSelector, BuildSelector,
@@ -339,13 +345,9 @@ def print_preamble(platform: str, options: Options, identifiers: list[str]) -> N
def get_build_identifiers( def get_build_identifiers(
platform: PlatformName, build_selector: BuildSelector, architectures: set[Architecture] platform: PlatformName, build_selector: BuildSelector, architectures: Set[Architecture]
) -> list[str]: ) -> list[str]:
python_configurations: ( python_configurations: Sequence[GenericPythonConfiguration]
list[cibuildwheel.linux.PythonConfiguration]
| list[cibuildwheel.windows.PythonConfiguration]
| list[cibuildwheel.macos.PythonConfiguration]
)
if platform == "linux": if platform == "linux":
python_configurations = cibuildwheel.linux.get_python_configurations( python_configurations = cibuildwheel.linux.get_python_configurations(
+2 -1
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
from collections.abc import Set
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path, PurePath, PurePosixPath from pathlib import Path, PurePath, PurePosixPath
from typing import Iterator, Tuple from typing import Iterator, Tuple
@@ -46,7 +47,7 @@ class BuildStep:
def get_python_configurations( def get_python_configurations(
build_selector: BuildSelector, build_selector: BuildSelector,
architectures: set[Architecture], architectures: Set[Architecture],
) -> list[PythonConfiguration]: ) -> list[PythonConfiguration]:
full_python_configs = read_python_configs("linux") full_python_configs = read_python_configs("linux")
+2 -1
View File
@@ -8,6 +8,7 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
from collections.abc import Set
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from typing import Sequence, Tuple, cast from typing import Sequence, Tuple, cast
@@ -69,7 +70,7 @@ class PythonConfiguration:
def get_python_configurations( def get_python_configurations(
build_selector: BuildSelector, architectures: set[Architecture] build_selector: BuildSelector, architectures: Set[Architecture]
) -> list[PythonConfiguration]: ) -> list[PythonConfiguration]:
full_python_configs = read_python_configs("macos") full_python_configs = read_python_configs("macos")
+6
View File
@@ -42,3 +42,9 @@ else:
PlatformName = Literal["linux", "macos", "windows"] PlatformName = Literal["linux", "macos", "windows"]
PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"} PLATFORMS: Final[set[PlatformName]] = {"linux", "macos", "windows"}
class GenericPythonConfiguration(Protocol):
@property
def identifier(self) -> str:
...
+2 -1
View File
@@ -6,6 +6,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
from collections.abc import Set
from dataclasses import dataclass from dataclasses import dataclass
from functools import lru_cache from functools import lru_cache
from pathlib import Path from pathlib import Path
@@ -71,7 +72,7 @@ class PythonConfiguration:
def get_python_configurations( def get_python_configurations(
build_selector: BuildSelector, build_selector: BuildSelector,
architectures: set[Architecture], architectures: Set[Architecture],
) -> list[PythonConfiguration]: ) -> list[PythonConfiguration]:
full_python_configs = read_python_configs("windows") full_python_configs = read_python_configs("windows")