def test_passthrough_evil(tmp_path, monkeypatch, env_var_value): args = get_default_command_line_arguments() args.package_dir = str(tmp_path) monkeypatch.setattr(platform_module, "machine", lambda: "x86_64") monkeypatch.setenv("CIBW_ENVIRONMENT_PASS_LINUX", "ENV_VAR") options = Options(platform="linux", command_line_arguments=args) monkeypatch.setenv("ENV_VAR", env_var_value) parsed_environment = options.build_options(identifier=None).environment assert parsed_environment.as_dictionary(prev_environment={}) == { "ENV_VAR": env_var_value }
def print_preamble(platform: str, options: Options, identifiers: list[str]) -> None: print( textwrap.dedent( """ _ _ _ _ _ _ _ ___|_| |_ _ _|_| |_| |_ _ _| |_ ___ ___| | | _| | . | | | | | . | | | | | -_| -_| | |___|_|___|___|_|_|___|_____|_|_|___|___|_| """ ) ) print(f"cibuildwheel version {cibuildwheel.__version__}\n") print("Build options:") print(f" platform: {platform!r}") print(textwrap.indent(options.summary(identifiers), " ")) print(f"Cache folder: {CIBW_CACHE_PATH}") warnings = detect_warnings(options=options, identifiers=identifiers) if warnings: print("\nWarnings:") for warning in warnings: print(" " + warning) print("\nHere we go!\n")
def test_passthrough(tmp_path, monkeypatch): with tmp_path.joinpath("pyproject.toml").open("w") as f: f.write(PYPROJECT_1) args = get_default_command_line_arguments() args.package_dir = str(tmp_path) monkeypatch.setattr(platform_module, "machine", lambda: "x86_64") monkeypatch.setenv("EXAMPLE_ENV", "ONE") options = Options(platform="linux", command_line_arguments=args) default_build_options = options.build_options(identifier=None) assert default_build_options.environment.as_dictionary( prev_environment={}) == { "FOO": "BAR", "EXAMPLE_ENV": "ONE", }
def detect_warnings(*, options: Options, identifiers: list[str]) -> list[str]: warnings = [] # warn about deprecated {python} and {pip} for option_name in ["test_command", "before_build"]: option_values = [getattr(options.build_options(i), option_name) for i in identifiers] if any(o and ("{python}" in o or "{pip}" in o) for o in option_values): # Reminder: in an f-string, double braces means literal single brace msg = ( f"{option_name}: '{{python}}' and '{{pip}}' are no longer needed, " "and will be removed in a future release. Simply use 'python' or 'pip' instead." ) warnings.append(msg) return warnings
def test_options_1(tmp_path, monkeypatch): with tmp_path.joinpath("pyproject.toml").open("w") as f: f.write(PYPROJECT_1) args = get_default_command_line_arguments() args.package_dir = str(tmp_path) monkeypatch.setattr(platform_module, "machine", lambda: "x86_64") options = Options(platform="linux", command_line_arguments=args) identifiers = get_build_identifiers( platform="linux", build_selector=options.globals.build_selector, architectures=options.globals.architectures, ) override_display = """\ test_command: 'pyproject' cp37-manylinux_x86_64: 'pyproject-override'""" print(options.summary(identifiers)) assert override_display in options.summary(identifiers) default_build_options = options.build_options(identifier=None) assert default_build_options.environment == parse_environment('FOO="BAR"') all_pinned_docker_images = _get_pinned_docker_images() pinned_x86_64_docker_image = all_pinned_docker_images["x86_64"] local = options.build_options("cp38-manylinux_x86_64") assert local.manylinux_images is not None assert local.test_command == "pyproject" assert local.manylinux_images["x86_64"] == pinned_x86_64_docker_image[ "manylinux1"] local = options.build_options("cp37-manylinux_x86_64") assert local.manylinux_images is not None assert local.test_command == "pyproject-override" assert local.manylinux_images["x86_64"] == pinned_x86_64_docker_image[ "manylinux2014"]
def test_linux_container_split(tmp_path: Path, monkeypatch): """ Tests splitting linux builds by container image and before_all """ args = get_default_command_line_arguments() args.platform = "linux" (tmp_path / "pyproject.toml").write_text( textwrap.dedent(""" [tool.cibuildwheel] manylinux-x86_64-image = "normal_container_image" manylinux-i686-image = "normal_container_image" build = "*-manylinux_x86_64" skip = "pp*" archs = "x86_64 i686" [[tool.cibuildwheel.overrides]] select = "cp{38,39,310}-*" manylinux-x86_64-image = "other_container_image" manylinux-i686-image = "other_container_image" [[tool.cibuildwheel.overrides]] select = "cp39-*" before-all = "echo 'a cp39-only command'" """)) monkeypatch.chdir(tmp_path) options = Options("linux", command_line_arguments=args) python_configurations = cibuildwheel.linux.get_python_configurations( options.globals.build_selector, options.globals.architectures) build_steps = list( cibuildwheel.linux.get_build_steps(options, python_configurations)) # helper functions to extract test info def identifiers(step): return [c.identifier for c in step.platform_configs] def before_alls(step): return [ options.build_options(c.identifier).before_all for c in step.platform_configs ] pprint(build_steps) assert build_steps[0].container_image == "normal_container_image" assert identifiers(build_steps[0]) == [ "cp36-manylinux_x86_64", "cp37-manylinux_x86_64", "cp311-manylinux_x86_64", ] assert before_alls(build_steps[0]) == ["", "", ""] assert build_steps[1].container_image == "other_container_image" assert identifiers( build_steps[1]) == ["cp38-manylinux_x86_64", "cp310-manylinux_x86_64"] assert before_alls(build_steps[1]) == ["", ""] assert build_steps[2].container_image == "other_container_image" assert identifiers(build_steps[2]) == ["cp39-manylinux_x86_64"] assert before_alls(build_steps[2]) == ["echo 'a cp39-only command'"]