chore: remove some string types (#2798)
This commit is contained in:
@@ -6,7 +6,7 @@ import sys
|
|||||||
import typing
|
import typing
|
||||||
from collections.abc import Set
|
from collections.abc import Set
|
||||||
from enum import StrEnum, auto
|
from enum import StrEnum, auto
|
||||||
from typing import Final, Literal
|
from typing import Final, Literal, Self
|
||||||
|
|
||||||
from cibuildwheel import errors
|
from cibuildwheel import errors
|
||||||
from cibuildwheel.typing import PlatformName
|
from cibuildwheel.typing import PlatformName
|
||||||
@@ -82,34 +82,34 @@ class Architecture(StrEnum):
|
|||||||
arm64_iphonesimulator = auto()
|
arm64_iphonesimulator = auto()
|
||||||
x86_64_iphonesimulator = auto()
|
x86_64_iphonesimulator = auto()
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def parse_config(config: str, platform: PlatformName) -> "set[Architecture]":
|
def parse_config(cls, config: str, platform: PlatformName) -> set[Self]:
|
||||||
result = set()
|
result = set()
|
||||||
for arch_str in re.split(r"[\s,]+", config):
|
for arch_str in re.split(r"[\s,]+", config):
|
||||||
match arch_str:
|
match arch_str:
|
||||||
case "auto":
|
case "auto":
|
||||||
result |= Architecture.auto_archs(platform=platform)
|
result |= cls.auto_archs(platform=platform)
|
||||||
case "native":
|
case "native":
|
||||||
if native_arch := Architecture.native_arch(platform=platform):
|
if native_arch := cls.native_arch(platform=platform):
|
||||||
result.add(native_arch)
|
result.add(native_arch)
|
||||||
case "all":
|
case "all":
|
||||||
result |= Architecture.all_archs(platform=platform)
|
result |= cls.all_archs(platform=platform)
|
||||||
case "auto64":
|
case "auto64":
|
||||||
result |= Architecture.bitness_archs(platform=platform, bitness="64")
|
result |= cls.bitness_archs(platform=platform, bitness="64")
|
||||||
case "auto32":
|
case "auto32":
|
||||||
result |= Architecture.bitness_archs(platform=platform, bitness="32")
|
result |= cls.bitness_archs(platform=platform, bitness="32")
|
||||||
case _:
|
case _:
|
||||||
try:
|
try:
|
||||||
result.add(Architecture(arch_str))
|
result.add(cls(arch_str))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
msg = f"Invalid architecture '{arch_str}'"
|
msg = f"Invalid architecture '{arch_str}'"
|
||||||
raise errors.ConfigurationError(msg) from e
|
raise errors.ConfigurationError(msg) from e
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def native_arch(platform: PlatformName) -> "Architecture | None":
|
def native_arch(cls, platform: PlatformName) -> Self | None:
|
||||||
native_machine = platform_module.machine()
|
native_machine = platform_module.machine()
|
||||||
native_architecture = Architecture(native_machine)
|
native_architecture = cls(native_machine)
|
||||||
|
|
||||||
# Cross-platform support. Used for --print-build-identifiers or docker builds.
|
# Cross-platform support. Used for --print-build-identifiers or docker builds.
|
||||||
host_platform: PlatformName = (
|
host_platform: PlatformName = (
|
||||||
@@ -119,15 +119,15 @@ class Architecture(StrEnum):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if platform == "pyodide":
|
if platform == "pyodide":
|
||||||
return Architecture.wasm32
|
return cls.wasm32
|
||||||
elif platform == "ios":
|
elif platform == "ios":
|
||||||
# Can only build for iOS on macOS. The "native" architecture is the
|
# Can only build for iOS on macOS. The "native" architecture is the
|
||||||
# simulator for the macOS native platform.
|
# simulator for the macOS native platform.
|
||||||
if host_platform == "macos":
|
if host_platform == "macos":
|
||||||
if native_architecture == Architecture.x86_64:
|
if native_architecture == cls.x86_64:
|
||||||
return Architecture.x86_64_iphonesimulator
|
return cls.x86_64_iphonesimulator
|
||||||
else:
|
else:
|
||||||
return Architecture.arm64_iphonesimulator
|
return cls.arm64_iphonesimulator
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -139,64 +139,64 @@ class Architecture(StrEnum):
|
|||||||
# can't build anything on this platform
|
# can't build anything on this platform
|
||||||
return None
|
return None
|
||||||
|
|
||||||
native_architecture = Architecture(synonym)
|
native_architecture = cls(synonym)
|
||||||
|
|
||||||
return native_architecture
|
return native_architecture
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def auto_archs(platform: PlatformName) -> "set[Architecture]":
|
def auto_archs(cls, platform: PlatformName) -> set[Self]:
|
||||||
native_arch = Architecture.native_arch(platform)
|
native_arch = cls.native_arch(platform)
|
||||||
if native_arch is None:
|
if native_arch is None:
|
||||||
return set() # can't build anything on this platform
|
return set() # can't build anything on this platform
|
||||||
result = {native_arch}
|
result = {native_arch}
|
||||||
|
|
||||||
match platform:
|
match platform:
|
||||||
case "windows" if Architecture.AMD64 in result:
|
case "windows" if cls.AMD64 in result:
|
||||||
result.add(Architecture.x86)
|
result.add(cls.x86)
|
||||||
case "ios" if native_arch == Architecture.arm64_iphonesimulator:
|
case "ios" if native_arch == cls.arm64_iphonesimulator:
|
||||||
# Also build the device wheel if we're on ARM64.
|
# Also build the device wheel if we're on ARM64.
|
||||||
result.add(Architecture.arm64_iphoneos)
|
result.add(cls.arm64_iphoneos)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def all_archs(platform: PlatformName) -> "set[Architecture]":
|
def all_archs(cls, platform: PlatformName) -> set[Self]:
|
||||||
all_archs_map = {
|
all_archs_map = {
|
||||||
"linux": {
|
"linux": {
|
||||||
Architecture.x86_64,
|
cls.x86_64,
|
||||||
Architecture.i686,
|
cls.i686,
|
||||||
Architecture.aarch64,
|
cls.aarch64,
|
||||||
Architecture.ppc64le,
|
cls.ppc64le,
|
||||||
Architecture.s390x,
|
cls.s390x,
|
||||||
Architecture.armv7l,
|
cls.armv7l,
|
||||||
Architecture.riscv64,
|
cls.riscv64,
|
||||||
},
|
},
|
||||||
"macos": {Architecture.x86_64, Architecture.arm64, Architecture.universal2},
|
"macos": {cls.x86_64, cls.arm64, cls.universal2},
|
||||||
"windows": {Architecture.x86, Architecture.AMD64, Architecture.ARM64},
|
"windows": {cls.x86, cls.AMD64, cls.ARM64},
|
||||||
"pyodide": {Architecture.wasm32},
|
"pyodide": {cls.wasm32},
|
||||||
"android": {Architecture.x86_64, Architecture.arm64_v8a},
|
"android": {cls.x86_64, cls.arm64_v8a},
|
||||||
"ios": {
|
"ios": {
|
||||||
Architecture.x86_64_iphonesimulator,
|
cls.x86_64_iphonesimulator,
|
||||||
Architecture.arm64_iphonesimulator,
|
cls.arm64_iphonesimulator,
|
||||||
Architecture.arm64_iphoneos,
|
cls.arm64_iphoneos,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return all_archs_map[platform]
|
return all_archs_map[platform]
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> "set[Architecture]":
|
def bitness_archs(cls, platform: PlatformName, bitness: Literal["64", "32"]) -> set[Self]:
|
||||||
# This map maps 64-bit architectures to their 32-bit equivalents.
|
# This map maps 64-bit architectures to their 32-bit equivalents.
|
||||||
archs_map = {
|
archs_map = {
|
||||||
Architecture.x86_64: Architecture.i686,
|
cls.x86_64: cls.i686,
|
||||||
Architecture.AMD64: Architecture.x86,
|
cls.AMD64: cls.x86,
|
||||||
Architecture.aarch64: Architecture.armv7l,
|
cls.aarch64: cls.armv7l,
|
||||||
}
|
}
|
||||||
native_arch = Architecture.native_arch(platform)
|
native_arch = cls.native_arch(platform)
|
||||||
|
|
||||||
if native_arch is None:
|
if native_arch is None:
|
||||||
return set() # can't build anything on this platform
|
return set() # can't build anything on this platform
|
||||||
|
|
||||||
if native_arch == Architecture.wasm32:
|
if native_arch == cls.wasm32:
|
||||||
return {native_arch} if bitness == "32" else set()
|
return {native_arch} if bitness == "32" else set()
|
||||||
|
|
||||||
match bitness:
|
match bitness:
|
||||||
@@ -206,7 +206,7 @@ class Architecture(StrEnum):
|
|||||||
if native_arch in archs_map.values():
|
if native_arch in archs_map.values():
|
||||||
return {native_arch}
|
return {native_arch}
|
||||||
elif native_arch in archs_map and platform in {"linux", "windows"}:
|
elif native_arch in archs_map and platform in {"linux", "windows"}:
|
||||||
if native_arch == Architecture.aarch64 and not _check_aarch32_el0():
|
if native_arch == cls.aarch64 and not _check_aarch32_el0():
|
||||||
# If we're on aarch64, skip if we cannot build armv7l wheels.
|
# If we're on aarch64, skip if we cannot build armv7l wheels.
|
||||||
return set()
|
return set()
|
||||||
return {archs_map[native_arch]}
|
return {archs_map[native_arch]}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class OCIPlatform(Enum):
|
|||||||
S390X = "linux/s390x"
|
S390X = "linux/s390x"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def native(cls) -> "OCIPlatform":
|
def native(cls) -> Self:
|
||||||
"""Return the current OCI platform, or raise ValueError if unknown."""
|
"""Return the current OCI platform, or raise ValueError if unknown."""
|
||||||
arch = platform.machine().lower()
|
arch = platform.machine().lower()
|
||||||
mapping = {
|
mapping = {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import dataclasses
|
|||||||
import itertools
|
import itertools
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
from typing import Any
|
from typing import Any, Self
|
||||||
|
|
||||||
import bracex
|
import bracex
|
||||||
from packaging.specifiers import SpecifierSet
|
from packaging.specifiers import SpecifierSet
|
||||||
@@ -37,11 +37,11 @@ class EnableGroup(StrEnum):
|
|||||||
PyodidePrerelease = "pyodide-prerelease"
|
PyodidePrerelease = "pyodide-prerelease"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all_groups(cls) -> frozenset["EnableGroup"]:
|
def all_groups(cls) -> frozenset[Self]:
|
||||||
return frozenset(cls)
|
return frozenset(cls)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_option_value(cls, value: str) -> frozenset["EnableGroup"]:
|
def parse_option_value(cls, value: str) -> frozenset[Self]:
|
||||||
"""
|
"""
|
||||||
Parses a string of space-separated values into a set of EnableGroup
|
Parses a string of space-separated values into a set of EnableGroup
|
||||||
members. The string may contain group names or "all".
|
members. The string may contain group names or "all".
|
||||||
|
|||||||
Reference in New Issue
Block a user