diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index a58186123..d27703152 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -275,6 +275,9 @@ def build(options: Options, tmp_path: Path) -> None: options.globals.build_selector, options.globals.architectures ) + if len(python_configurations) == 0: + return + try: before_all_options_identifier = python_configurations[0].identifier before_all_options = options.build_options(before_all_options_identifier) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index ef85a72c6..5015d3487 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -435,6 +435,10 @@ class FileReport(NamedTuple): FileReport(wheel.name, f"{(wheel.stat().st_size + 1023) // 1024:,d}") for wheel in final_contents - existing_contents ] + + if len(new_contents) == 0: + return + max_name_len = max(len(f.name) for f in new_contents) max_size_len = max(len(f.size) for f in new_contents) n = len(new_contents) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 86d01fa82..13b5c0c3d 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -234,6 +234,9 @@ def build(options: Options, tmp_path: Path) -> None: options.globals.build_selector, options.globals.architectures ) + if len(python_configurations) == 0: + return + try: before_all_options_identifier = python_configurations[0].identifier before_all_options = options.build_options(before_all_options_identifier) diff --git a/test/test_0_basic.py b/test/test_0_basic.py index ec72483a3..2d2e8d97f 100644 --- a/test/test_0_basic.py +++ b/test/test_0_basic.py @@ -59,3 +59,19 @@ def test_build_identifiers(tmp_path): assert len(expected_wheels) == len( build_identifiers ), f"{expected_wheels} vs {build_identifiers}" + + +def test_allow_empty(tmp_path): + project_dir = tmp_path / "project" + basic_project.generate(project_dir) + + # Sanity check - --allow-empty should cause a no-op build to complete + # without error + actual_wheels = utils.cibuildwheel_run( + project_dir, + add_env={"CIBW_BUILD": "BUILD_NOTHING_AT_ALL"}, + add_args=["--allow-empty"], + ) + + # check that nothing was built + assert len(actual_wheels) == 0 diff --git a/test/utils.py b/test/utils.py index 0248a7c15..86df69a40 100644 --- a/test/utils.py +++ b/test/utils.py @@ -44,7 +44,9 @@ def cibuildwheel_get_build_identifiers(project_path, env=None, *, prerelease_pyt return cmd_output.strip().split("\n") -def cibuildwheel_run(project_path, package_dir=".", env=None, add_env=None, output_dir=None): +def cibuildwheel_run( + project_path, package_dir=".", env=None, add_env=None, output_dir=None, add_args=None +): """ Runs cibuildwheel as a subprocess, building the project at project_path. @@ -57,6 +59,7 @@ def cibuildwheel_run(project_path, package_dir=".", env=None, add_env=None, outp :param add_env: environment used to update env :param output_dir: directory where wheels are saved. If None, a temporary directory will be used for the duration of the command. + :param add_args: Additional command-line arguments to pass to cibuildwheel. :return: list of built wheels (file names). """ if env is None: @@ -64,6 +67,9 @@ def cibuildwheel_run(project_path, package_dir=".", env=None, add_env=None, outp # If present in the host environment, remove the MACOSX_DEPLOYMENT_TARGET for consistency env.pop("MACOSX_DEPLOYMENT_TARGET", None) + if add_args is None: + add_args = [] + if add_env is not None: env.update(add_env) @@ -77,6 +83,7 @@ def cibuildwheel_run(project_path, package_dir=".", env=None, add_env=None, outp "--output-dir", str(output_dir or tmp_output_dir), str(package_dir), + *add_args, ], env=env, cwd=project_path,