From 61b94434b287b4c432240787657a6aa8f780ebca Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Mon, 18 Jan 2021 01:03:15 -0500 Subject: [PATCH] fix: error if build selectors are empty --- cibuildwheel/__main__.py | 7 ++++--- pyproject.toml | 6 ++++++ unit_test/main_tests/conftest.py | 9 +++++++++ unit_test/main_tests/main_options_test.py | 23 ++++++++++++++++++++++ unit_test/main_tests/main_platform_test.py | 5 +++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 8bac5e5d..068897dc 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -195,9 +195,6 @@ def main() -> None: archs = Architecture.parse_config(archs_config_str, platform=platform) identifiers = get_build_identifiers(platform, build_selector, archs) - if not identifiers: - print("ERROR: No build identifiers selected!") - sys.exit(3) if args.print_build_identifiers: for identifier in identifiers: @@ -269,6 +266,10 @@ def main() -> None: else: assert_never(platform) + if not identifiers: + print("ERROR: No build identifiers selected!") + sys.exit(3) + def detect_obsolete_options() -> None: # Check the old 'MANYLINUX1_*_IMAGE' options diff --git a/pyproject.toml b/pyproject.toml index 285367ae..c05fec7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,3 +5,9 @@ requires = [ ] build-backend = "setuptools.build_meta" + + +[tool.pytest.ini_options] +markers = [ + "allow_empty(platform): Allow main tests on this platform(s) to be empty", +] diff --git a/unit_test/main_tests/conftest.py b/unit_test/main_tests/conftest.py index 1122a88c..c9ae6e8a 100644 --- a/unit_test/main_tests/conftest.py +++ b/unit_test/main_tests/conftest.py @@ -59,6 +59,15 @@ def fake_package_dir(monkeypatch): def platform(request, monkeypatch): platform_value = request.param monkeypatch.setenv('CIBW_PLATFORM', platform_value) + + marker = request.node.get_closest_marker('allow_empty') + if marker is not None and (len(marker.args) == 0 or platform_value in marker.args): + def pass_exit(val: int): + if val not in {3}: + sys.exit(val) + + monkeypatch.setattr(sys, 'exit', pass_exit) + return platform_value diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index f28b1ed4..fef74203 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -11,6 +11,7 @@ from cibuildwheel.util import BuildSelector # CIBW_PLATFORM is tested in main_platform_test.py +@pytest.mark.allow_empty('windows') def test_output_dir(platform, intercepted_build_args, monkeypatch): OUTPUT_DIR = Path('some_output_dir') @@ -21,12 +22,14 @@ def test_output_dir(platform, intercepted_build_args, monkeypatch): assert intercepted_build_args.args[0].output_dir == OUTPUT_DIR +@pytest.mark.allow_empty('windows') def test_output_dir_default(platform, intercepted_build_args, monkeypatch): main() assert intercepted_build_args.args[0].output_dir == Path('wheelhouse') +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('also_set_environment', [False, True]) def test_output_dir_argument(also_set_environment, platform, intercepted_build_args, monkeypatch): OUTPUT_DIR = Path('some_output_dir') @@ -40,6 +43,7 @@ def test_output_dir_argument(also_set_environment, platform, intercepted_build_a assert intercepted_build_args.args[0].output_dir == OUTPUT_DIR +@pytest.mark.allow_empty def test_build_selector(platform, intercepted_build_args, monkeypatch): BUILD = 'some build* *-selector' SKIP = 'some skip* *-selector' @@ -57,6 +61,16 @@ def test_build_selector(platform, intercepted_build_args, monkeypatch): # Unit tests for BuildSelector are in build_selector_test.py +def test_empty_selector(platform, intercepted_build_args, monkeypatch): + monkeypatch.setenv('CIBW_SKIP', '*') + + with pytest.raises(SystemExit) as e: + main() + + assert e.value.code == 3 + + +@pytest.mark.allow_empty @pytest.mark.parametrize('architecture, image, full_image', [ ('x86_64', None, 'quay.io/pypa/manylinux2010_x86_64:*'), ('x86_64', 'manylinux1', 'quay.io/pypa/manylinux1_x86_64:*'), @@ -100,6 +114,7 @@ def get_default_repair_command(platform): raise ValueError('Unknown platform', platform) +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('repair_command', [None, 'repair', 'repair -w {dest_dir} {wheel}']) @pytest.mark.parametrize('platform_specific', [False, True]) def test_repair_command(repair_command, platform_specific, platform, intercepted_build_args, monkeypatch): @@ -116,6 +131,7 @@ def test_repair_command(repair_command, platform_specific, platform, intercepted assert intercepted_build_args.args[0].repair_command == expected_repair +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('environment', [ {}, {'something': 'value'}, @@ -137,6 +153,7 @@ def test_environment(environment, platform_specific, platform, intercepted_build assert intercepted_environment.as_dictionary(prev_environment={}) == environment +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('test_requires', [None, 'requirement other_requirement']) @pytest.mark.parametrize('platform_specific', [False, True]) def test_test_requires(test_requires, platform_specific, platform, intercepted_build_args, monkeypatch): @@ -152,6 +169,7 @@ def test_test_requires(test_requires, platform_specific, platform, intercepted_b assert intercepted_build_args.args[0].test_requires == (test_requires or '').split() +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('test_extras', [None, 'extras']) @pytest.mark.parametrize('platform_specific', [False, True]) def test_test_extras(test_extras, platform_specific, platform, intercepted_build_args, monkeypatch): @@ -167,6 +185,7 @@ def test_test_extras(test_extras, platform_specific, platform, intercepted_build assert intercepted_build_args.args[0].test_extras == ('[' + test_extras + ']' if test_extras else '') +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('test_command', [None, 'test --command']) @pytest.mark.parametrize('platform_specific', [False, True]) def test_test_command(test_command, platform_specific, platform, intercepted_build_args, monkeypatch): @@ -182,6 +201,7 @@ def test_test_command(test_command, platform_specific, platform, intercepted_bui assert intercepted_build_args.args[0].test_command == test_command +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('before_build', [None, 'before --build']) @pytest.mark.parametrize('platform_specific', [False, True]) def test_before_build(before_build, platform_specific, platform, intercepted_build_args, monkeypatch): @@ -197,6 +217,7 @@ def test_before_build(before_build, platform_specific, platform, intercepted_bui assert intercepted_build_args.args[0].before_build == before_build +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('build_verbosity', [None, 0, 2, -2, 4, -4]) @pytest.mark.parametrize('platform_specific', [False, True]) def test_build_verbosity(build_verbosity, platform_specific, platform, intercepted_build_args, monkeypatch): @@ -213,6 +234,7 @@ def test_build_verbosity(build_verbosity, platform_specific, platform, intercept assert intercepted_build_args.args[0].build_verbosity == expected_verbosity +@pytest.mark.allow_empty @pytest.mark.parametrize('option_name', ['CIBW_BUILD', 'CIBW_SKIP']) @pytest.mark.parametrize('option_value, build_selector_patterns', [ ('*-manylinux1_*', ['*-manylinux_*']), @@ -234,6 +256,7 @@ def test_build_selector_migrations(intercepted_build_args, monkeypatch, option_n assert intercepted_build_selector.skip_patterns == build_selector_patterns +@pytest.mark.allow_empty @pytest.mark.parametrize('before_all', ["", None, 'test text']) @pytest.mark.parametrize('platform_specific', [False, True]) def test_before_all(before_all, platform_specific, platform, intercepted_build_args, monkeypatch): diff --git a/unit_test/main_tests/main_platform_test.py b/unit_test/main_tests/main_platform_test.py index 9b7c06fe..6445f331 100644 --- a/unit_test/main_tests/main_platform_test.py +++ b/unit_test/main_tests/main_platform_test.py @@ -52,6 +52,7 @@ def test_unknown_platform(monkeypatch, capsys): assert 'cibuildwheel: Unsupported platform: nonexistent' in err +@pytest.mark.allow_empty('windows') def test_platform_argument(platform, intercepted_build_args, monkeypatch): monkeypatch.setenv('CIBW_PLATFORM', 'nonexistent') monkeypatch.setattr(sys, 'argv', sys.argv + ['--platform', platform]) @@ -61,12 +62,14 @@ def test_platform_argument(platform, intercepted_build_args, monkeypatch): assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR +@pytest.mark.allow_empty('windows') def test_platform_environment(platform, intercepted_build_args, monkeypatch): main() assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR +@pytest.mark.allow_empty('windows') def test_archs_default(platform, intercepted_build_args, monkeypatch): monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') @@ -79,6 +82,7 @@ def test_archs_default(platform, intercepted_build_args, monkeypatch): assert build_options.architectures == {Architecture.x86_64} +@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('use_env_var', [False, True]) def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_var): monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') @@ -112,6 +116,7 @@ def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch): assert build_options.architectures == {Architecture.x86_64} +@pytest.mark.allow_empty('windows') def test_archs_platform_native(platform, intercepted_build_args, monkeypatch): monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') monkeypatch.setenv('CIBW_ARCHS', 'native')