@@ -244,6 +244,28 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
244
244
return _compute_platform_ci ()
245
245
246
246
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
+
247
269
def build_in_directory (args : CommandLineArguments ) -> None :
248
270
platform : PlatformName = _compute_platform (args )
249
271
options = compute_options (platform = platform , command_line_arguments = args , env = os .environ )
@@ -257,8 +279,9 @@ def build_in_directory(args: CommandLineArguments) -> None:
257
279
print (msg , file = sys .stderr )
258
280
sys .exit (2 )
259
281
282
+ platform_module = get_platform_module (platform )
260
283
identifiers = get_build_identifiers (
261
- platform = platform ,
284
+ platform_module = platform_module ,
262
285
build_selector = options .globals .build_selector ,
263
286
architectures = options .globals .architectures ,
264
287
)
@@ -304,14 +327,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
304
327
with cibuildwheel .util .print_new_wheels (
305
328
"\n {n} wheels produced in {m:.0f} minutes:" , output_dir
306
329
):
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 )
315
331
finally :
316
332
# avoid https://github.com/python/cpython/issues/86962 by performing
317
333
# cleanup manually
@@ -354,25 +370,9 @@ def print_preamble(platform: str, options: Options, identifiers: list[str]) -> N
354
370
355
371
356
372
def get_build_identifiers (
357
- platform : PlatformName , build_selector : BuildSelector , architectures : Set [Architecture ]
373
+ platform_module : PlatformModule , build_selector : BuildSelector , architectures : Set [Architecture ]
358
374
) -> 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 )
376
376
return [config .identifier for config in python_configurations ]
377
377
378
378
0 commit comments