File tree 4 files changed +39
-5
lines changed
4 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -334,7 +334,7 @@ def build_in_directory(args: CommandLineArguments) -> None:
334
334
335
335
if not identifiers :
336
336
message = f"No build identifiers selected: { options .globals .build_selector } "
337
- if args .allow_empty :
337
+ if options . globals .allow_empty :
338
338
print (f"cibuildwheel: { message } " , file = sys .stderr )
339
339
else :
340
340
raise errors .NothingToDoError (message )
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ class GlobalOptions:
75
75
build_selector : BuildSelector
76
76
test_selector : TestSelector
77
77
architectures : set [Architecture ]
78
+ allow_empty : bool
78
79
79
80
80
81
@dataclasses .dataclass (frozen = True )
@@ -520,6 +521,8 @@ def globals(self) -> GlobalOptions:
520
521
self .reader .get ("free-threaded-support" , env_plat = False , ignore_empty = True )
521
522
)
522
523
524
+ allow_empty = args .allow_empty or strtobool (self .env .get ("CIBW_ALLOW_EMPTY" , "0" ))
525
+
523
526
prerelease_pythons = args .prerelease_pythons or strtobool (
524
527
self .env .get ("CIBW_PRERELEASE_PYTHONS" , "0" )
525
528
)
@@ -557,6 +560,7 @@ def globals(self) -> GlobalOptions:
557
560
build_selector = build_selector ,
558
561
test_selector = test_selector ,
559
562
architectures = architectures ,
563
+ allow_empty = allow_empty ,
560
564
)
561
565
562
566
def build_options (self , identifier : str | None ) -> BuildOptions :
Original file line number Diff line number Diff line change @@ -621,6 +621,28 @@ This option can also be set using the [command-line option](#command-line) `--pr
621
621
CIBW_PRERELEASE_PYTHONS: True
622
622
```
623
623
624
+ ### ` CIBW_ALLOW_EMPTY ` {: #allow-empty}
625
+ > Suppress the error code if no wheels match the specified build identifiers
626
+
627
+ When none of the specified build identifiers match any available versions,
628
+ cibuildwheel will typically return error code 3, indicating that there are
629
+ no wheels to build. Enabling this option will suppress this error, allowing
630
+ the build process to complete without signaling an error.
631
+
632
+ Default: Off (0). Error code 3 is returned when no builds are selected.
633
+
634
+ This option can also be set using the [ command-line option] ( #command-line )
635
+ ` --allow-empty ` . This option is not available in the ` pyproject.toml ` config.
636
+
637
+ #### Examples
638
+
639
+ !!! tab examples "Environment variables"
640
+
641
+ ```yaml
642
+ # Prevent an error code if the build does not match any wheels
643
+ CIBW_ALLOW_EMPTY: True
644
+ ```
645
+
624
646
## Build customization
625
647
626
648
### ` CIBW_BUILD_FRONTEND ` {: #build-frontend}
@@ -1667,7 +1689,7 @@ cibuildwheel exits 0 on success, or >0 if an error occurs.
1667
1689
Specific error codes are defined:
1668
1690
1669
1691
- 2 means a configuration error
1670
- - 3 means no builds are selected (and --allow-empty wasn't passed)
1692
+ - 3 means no builds are selected (and [ ` --allow-empty ` ] ( #allow-empty ) wasn't passed)
1671
1693
- 4 means you specified an option that has been deprecated.
1672
1694
1673
1695
Original file line number Diff line number Diff line change @@ -69,16 +69,24 @@ def test_build_identifiers(tmp_path):
69
69
), f"{ expected_wheels } vs { build_identifiers } "
70
70
71
71
72
- def test_allow_empty (tmp_path ):
72
+ @pytest .mark .parametrize (
73
+ ("add_args" , "env_allow_empty" ),
74
+ [
75
+ (["--allow-empty" ], {}),
76
+ (["--allow-empty" ], {"CIBW_ALLOW_EMPTY" : "0" }),
77
+ (None , {"CIBW_ALLOW_EMPTY" : "1" }),
78
+ ],
79
+ )
80
+ def test_allow_empty (tmp_path , add_args , env_allow_empty ):
73
81
project_dir = tmp_path / "project"
74
82
basic_project .generate (project_dir )
75
83
76
84
# Sanity check - --allow-empty should cause a no-op build to complete
77
85
# without error
78
86
actual_wheels = utils .cibuildwheel_run (
79
87
project_dir ,
80
- add_env = {"CIBW_BUILD" : "BUILD_NOTHING_AT_ALL" },
81
- add_args = [ "--allow-empty" ] ,
88
+ add_env = {"CIBW_BUILD" : "BUILD_NOTHING_AT_ALL" , ** env_allow_empty },
89
+ add_args = add_args ,
82
90
)
83
91
84
92
# check that nothing was built
You can’t perform that action at this time.
0 commit comments