@@ -244,6 +244,28 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
244244 return _compute_platform_ci ()
245245
246246
247+ class PlatformModule (typing .Protocol ):
248+ # note that as per PEP544, the self argument is ignored when the protocol
249+ # is applied to a module
250+ def get_python_configurations (
251+ self , build_selector : BuildSelector , architectures : Set [Architecture ]
252+ ) -> Sequence [GenericPythonConfiguration ]:
253+ ...
254+
255+ def build (self , options : Options , tmp_path : Path ) -> None :
256+ ...
257+
258+
259+ def get_platform_module (platform : PlatformName ) -> PlatformModule :
260+ if platform == "linux" :
261+ return cibuildwheel .linux
262+ if platform == "windows" :
263+ return cibuildwheel .windows
264+ if platform == "macos" :
265+ return cibuildwheel .macos
266+ assert_never (platform ) # noqa: RET503
267+
268+
247269def build_in_directory (args : CommandLineArguments ) -> None :
248270 platform : PlatformName = _compute_platform (args )
249271 options = compute_options (platform = platform , command_line_arguments = args , env = os .environ )
@@ -257,8 +279,9 @@ def build_in_directory(args: CommandLineArguments) -> None:
257279 print (msg , file = sys .stderr )
258280 sys .exit (2 )
259281
282+ platform_module = get_platform_module (platform )
260283 identifiers = get_build_identifiers (
261- platform = platform ,
284+ platform_module = platform_module ,
262285 build_selector = options .globals .build_selector ,
263286 architectures = options .globals .architectures ,
264287 )
@@ -304,14 +327,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
304327 with cibuildwheel .util .print_new_wheels (
305328 "\n {n} wheels produced in {m:.0f} minutes:" , output_dir
306329 ):
307- if platform == "linux" :
308- cibuildwheel .linux .build (options , tmp_path )
309- elif platform == "windows" :
310- cibuildwheel .windows .build (options , tmp_path )
311- elif platform == "macos" :
312- cibuildwheel .macos .build (options , tmp_path )
313- else :
314- assert_never (platform )
330+ platform_module .build (options , tmp_path )
315331 finally :
316332 # avoid https://github.com/python/cpython/issues/86962 by performing
317333 # cleanup manually
@@ -354,25 +370,9 @@ def print_preamble(platform: str, options: Options, identifiers: list[str]) -> N
354370
355371
356372def get_build_identifiers (
357- platform : PlatformName , build_selector : BuildSelector , architectures : Set [Architecture ]
373+ platform_module : PlatformModule , build_selector : BuildSelector , architectures : Set [Architecture ]
358374) -> list [str ]:
359- python_configurations : Sequence [GenericPythonConfiguration ]
360-
361- if platform == "linux" :
362- python_configurations = cibuildwheel .linux .get_python_configurations (
363- build_selector , architectures
364- )
365- elif platform == "windows" :
366- python_configurations = cibuildwheel .windows .get_python_configurations (
367- build_selector , architectures
368- )
369- elif platform == "macos" :
370- python_configurations = cibuildwheel .macos .get_python_configurations (
371- build_selector , architectures
372- )
373- else :
374- assert_never (platform )
375-
375+ python_configurations = platform_module .get_python_configurations (build_selector , architectures )
376376 return [config .identifier for config in python_configurations ]
377377
378378
0 commit comments