11
11
from ._compat .typing import assert_never
12
12
from .architecture import Architecture
13
13
from .logger import log
14
- from .oci_container import OCIContainer
15
- from .options import Options
14
+ from .oci_container import OCIContainer , OCIContainerEngineConfig
15
+ from .options import BuildOptions , Options
16
16
from .typing import PathOrStr
17
17
from .util import (
18
18
AlreadyBuiltWheelError ,
@@ -44,6 +44,7 @@ def path(self) -> PurePosixPath:
44
44
class BuildStep :
45
45
platform_configs : list [PythonConfiguration ]
46
46
platform_tag : str
47
+ container_engine : OCIContainerEngineConfig
47
48
container_image : str
48
49
49
50
@@ -65,8 +66,9 @@ def get_python_configurations(
65
66
]
66
67
67
68
68
- def container_image_for_python_configuration (config : PythonConfiguration , options : Options ) -> str :
69
- build_options = options .build_options (config .identifier )
69
+ def container_image_for_python_configuration (
70
+ config : PythonConfiguration , build_options : BuildOptions
71
+ ) -> str :
70
72
# e.g
71
73
# identifier is 'cp310-manylinux_x86_64'
72
74
# platform_tag is 'manylinux_x86_64'
@@ -91,22 +93,26 @@ def get_build_steps(
91
93
Groups PythonConfigurations into BuildSteps. Each BuildStep represents a
92
94
separate container instance.
93
95
"""
94
- steps = OrderedDict [Tuple [str , str , str ], BuildStep ]()
96
+ steps = OrderedDict [Tuple [str , str , str , OCIContainerEngineConfig ], BuildStep ]()
95
97
96
98
for config in python_configurations :
97
99
_ , platform_tag = config .identifier .split ("-" , 1 )
98
100
99
- before_all = options .build_options (config .identifier ).before_all
100
- container_image = container_image_for_python_configuration (config , options )
101
+ build_options = options .build_options (config .identifier )
102
+
103
+ before_all = build_options .before_all
104
+ container_image = container_image_for_python_configuration (config , build_options )
105
+ container_engine = build_options .container_engine
101
106
102
- step_key = (platform_tag , container_image , before_all )
107
+ step_key = (platform_tag , container_image , before_all , container_engine )
103
108
104
109
if step_key in steps :
105
110
steps [step_key ].platform_configs .append (config )
106
111
else :
107
112
steps [step_key ] = BuildStep (
108
113
platform_configs = [config ],
109
114
platform_tag = platform_tag ,
115
+ container_engine = container_engine ,
110
116
container_image = container_image ,
111
117
)
112
118
@@ -388,29 +394,6 @@ def build_in_container(
388
394
389
395
390
396
def build (options : Options , tmp_path : Path ) -> None : # noqa: ARG001
391
- try :
392
- # check the container engine is installed
393
- subprocess .run (
394
- [options .globals .container_engine .name , "--version" ],
395
- check = True ,
396
- stdout = subprocess .DEVNULL ,
397
- )
398
- except subprocess .CalledProcessError :
399
- print (
400
- unwrap (
401
- f"""
402
- cibuildwheel: { options .globals .container_engine } not found. An
403
- OCI exe like Docker or Podman is required to run Linux builds.
404
- If you're building on Travis CI, add `services: [docker]` to
405
- your .travis.yml. If you're building on Circle CI in Linux,
406
- add a `setup_remote_docker` step to your .circleci/config.yml.
407
- If you're building on Cirrus CI, use `docker_builder` task.
408
- """
409
- ),
410
- file = sys .stderr ,
411
- )
412
- sys .exit (2 )
413
-
414
397
python_configurations = get_python_configurations (
415
398
options .globals .build_selector , options .globals .architectures
416
399
)
@@ -425,6 +408,29 @@ def build(options: Options, tmp_path: Path) -> None: # noqa: ARG001
425
408
container_package_dir = container_project_path / abs_package_dir .relative_to (cwd )
426
409
427
410
for build_step in get_build_steps (options , python_configurations ):
411
+ try :
412
+ # check the container engine is installed
413
+ subprocess .run (
414
+ [build_step .container_engine .name , "--version" ],
415
+ check = True ,
416
+ stdout = subprocess .DEVNULL ,
417
+ )
418
+ except subprocess .CalledProcessError :
419
+ print (
420
+ unwrap (
421
+ f"""
422
+ cibuildwheel: { build_step .container_engine .name } not found. An
423
+ OCI exe like Docker or Podman is required to run Linux builds.
424
+ If you're building on Travis CI, add `services: [docker]` to
425
+ your .travis.yml. If you're building on Circle CI in Linux,
426
+ add a `setup_remote_docker` step to your .circleci/config.yml.
427
+ If you're building on Cirrus CI, use `docker_builder` task.
428
+ """
429
+ ),
430
+ file = sys .stderr ,
431
+ )
432
+ sys .exit (2 )
433
+
428
434
try :
429
435
ids_to_build = [x .identifier for x in build_step .platform_configs ]
430
436
log .step (f"Starting container image { build_step .container_image } ..." )
@@ -435,7 +441,7 @@ def build(options: Options, tmp_path: Path) -> None: # noqa: ARG001
435
441
image = build_step .container_image ,
436
442
enforce_32_bit = build_step .platform_tag .endswith ("i686" ),
437
443
cwd = container_project_path ,
438
- engine = options . globals .container_engine ,
444
+ engine = build_step .container_engine ,
439
445
) as container :
440
446
build_in_container (
441
447
options = options ,
0 commit comments