66import typing
77from collections .abc import Set
88from enum import StrEnum , auto
9- from typing import Final , Literal
9+ from typing import Final , Literal , Self
1010
1111from cibuildwheel import errors
1212from cibuildwheel .typing import PlatformName
@@ -82,34 +82,34 @@ class Architecture(StrEnum):
8282 arm64_iphonesimulator = auto ()
8383 x86_64_iphonesimulator = auto ()
8484
85- @staticmethod
86- def parse_config (config : str , platform : PlatformName ) -> " set[Architecture]" :
85+ @classmethod
86+ def parse_config (cls , config : str , platform : PlatformName ) -> set [Self ] :
8787 result = set ()
8888 for arch_str in re .split (r"[\s,]+" , config ):
8989 match arch_str :
9090 case "auto" :
91- result |= Architecture .auto_archs (platform = platform )
91+ result |= cls .auto_archs (platform = platform )
9292 case "native" :
93- if native_arch := Architecture .native_arch (platform = platform ):
93+ if native_arch := cls .native_arch (platform = platform ):
9494 result .add (native_arch )
9595 case "all" :
96- result |= Architecture .all_archs (platform = platform )
96+ result |= cls .all_archs (platform = platform )
9797 case "auto64" :
98- result |= Architecture .bitness_archs (platform = platform , bitness = "64" )
98+ result |= cls .bitness_archs (platform = platform , bitness = "64" )
9999 case "auto32" :
100- result |= Architecture .bitness_archs (platform = platform , bitness = "32" )
100+ result |= cls .bitness_archs (platform = platform , bitness = "32" )
101101 case _:
102102 try :
103- result .add (Architecture (arch_str ))
103+ result .add (cls (arch_str ))
104104 except ValueError as e :
105105 msg = f"Invalid architecture '{ arch_str } '"
106106 raise errors .ConfigurationError (msg ) from e
107107 return result
108108
109- @staticmethod
110- def native_arch (platform : PlatformName ) -> "Architecture | None" :
109+ @classmethod
110+ def native_arch (cls , platform : PlatformName ) -> Self | None :
111111 native_machine = platform_module .machine ()
112- native_architecture = Architecture (native_machine )
112+ native_architecture = cls (native_machine )
113113
114114 # Cross-platform support. Used for --print-build-identifiers or docker builds.
115115 host_platform : PlatformName = (
@@ -119,15 +119,15 @@ def native_arch(platform: PlatformName) -> "Architecture | None":
119119 )
120120
121121 if platform == "pyodide" :
122- return Architecture .wasm32
122+ return cls .wasm32
123123 elif platform == "ios" :
124124 # Can only build for iOS on macOS. The "native" architecture is the
125125 # simulator for the macOS native platform.
126126 if host_platform == "macos" :
127- if native_architecture == Architecture .x86_64 :
128- return Architecture .x86_64_iphonesimulator
127+ if native_architecture == cls .x86_64 :
128+ return cls .x86_64_iphonesimulator
129129 else :
130- return Architecture .arm64_iphonesimulator
130+ return cls .arm64_iphonesimulator
131131 else :
132132 return None
133133
@@ -139,64 +139,64 @@ def native_arch(platform: PlatformName) -> "Architecture | None":
139139 # can't build anything on this platform
140140 return None
141141
142- native_architecture = Architecture (synonym )
142+ native_architecture = cls (synonym )
143143
144144 return native_architecture
145145
146- @staticmethod
147- def auto_archs (platform : PlatformName ) -> " set[Architecture]" :
148- native_arch = Architecture .native_arch (platform )
146+ @classmethod
147+ def auto_archs (cls , platform : PlatformName ) -> set [Self ] :
148+ native_arch = cls .native_arch (platform )
149149 if native_arch is None :
150150 return set () # can't build anything on this platform
151151 result = {native_arch }
152152
153153 match platform :
154- case "windows" if Architecture .AMD64 in result :
155- result .add (Architecture .x86 )
156- case "ios" if native_arch == Architecture .arm64_iphonesimulator :
154+ case "windows" if cls .AMD64 in result :
155+ result .add (cls .x86 )
156+ case "ios" if native_arch == cls .arm64_iphonesimulator :
157157 # Also build the device wheel if we're on ARM64.
158- result .add (Architecture .arm64_iphoneos )
158+ result .add (cls .arm64_iphoneos )
159159
160160 return result
161161
162- @staticmethod
163- def all_archs (platform : PlatformName ) -> " set[Architecture]" :
162+ @classmethod
163+ def all_archs (cls , platform : PlatformName ) -> set [Self ] :
164164 all_archs_map = {
165165 "linux" : {
166- Architecture .x86_64 ,
167- Architecture .i686 ,
168- Architecture .aarch64 ,
169- Architecture .ppc64le ,
170- Architecture .s390x ,
171- Architecture .armv7l ,
172- Architecture .riscv64 ,
166+ cls .x86_64 ,
167+ cls .i686 ,
168+ cls .aarch64 ,
169+ cls .ppc64le ,
170+ cls .s390x ,
171+ cls .armv7l ,
172+ cls .riscv64 ,
173173 },
174- "macos" : {Architecture .x86_64 , Architecture .arm64 , Architecture .universal2 },
175- "windows" : {Architecture .x86 , Architecture .AMD64 , Architecture .ARM64 },
176- "pyodide" : {Architecture .wasm32 },
177- "android" : {Architecture .x86_64 , Architecture .arm64_v8a },
174+ "macos" : {cls .x86_64 , cls .arm64 , cls .universal2 },
175+ "windows" : {cls .x86 , cls .AMD64 , cls .ARM64 },
176+ "pyodide" : {cls .wasm32 },
177+ "android" : {cls .x86_64 , cls .arm64_v8a },
178178 "ios" : {
179- Architecture .x86_64_iphonesimulator ,
180- Architecture .arm64_iphonesimulator ,
181- Architecture .arm64_iphoneos ,
179+ cls .x86_64_iphonesimulator ,
180+ cls .arm64_iphonesimulator ,
181+ cls .arm64_iphoneos ,
182182 },
183183 }
184184 return all_archs_map [platform ]
185185
186- @staticmethod
187- def bitness_archs (platform : PlatformName , bitness : Literal ["64" , "32" ]) -> " set[Architecture]" :
186+ @classmethod
187+ def bitness_archs (cls , platform : PlatformName , bitness : Literal ["64" , "32" ]) -> set [Self ] :
188188 # This map maps 64-bit architectures to their 32-bit equivalents.
189189 archs_map = {
190- Architecture .x86_64 : Architecture .i686 ,
191- Architecture .AMD64 : Architecture .x86 ,
192- Architecture .aarch64 : Architecture .armv7l ,
190+ cls .x86_64 : cls .i686 ,
191+ cls .AMD64 : cls .x86 ,
192+ cls .aarch64 : cls .armv7l ,
193193 }
194- native_arch = Architecture .native_arch (platform )
194+ native_arch = cls .native_arch (platform )
195195
196196 if native_arch is None :
197197 return set () # can't build anything on this platform
198198
199- if native_arch == Architecture .wasm32 :
199+ if native_arch == cls .wasm32 :
200200 return {native_arch } if bitness == "32" else set ()
201201
202202 match bitness :
@@ -206,7 +206,7 @@ def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> "set[
206206 if native_arch in archs_map .values ():
207207 return {native_arch }
208208 elif native_arch in archs_map and platform in {"linux" , "windows" }:
209- if native_arch == Architecture .aarch64 and not _check_aarch32_el0 ():
209+ if native_arch == cls .aarch64 and not _check_aarch32_el0 ():
210210 # If we're on aarch64, skip if we cannot build armv7l wheels.
211211 return set ()
212212 return {archs_map [native_arch ]}
0 commit comments