diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index f8158b31..03b18a20 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -46,7 +46,7 @@ def main() -> None: auto-detected platform or to run cibuildwheel on your development machine. Specifying "macos" or "windows" only works on that operating system, but "linux" works on all three, as long as - Docker is installed. Default: auto. + Docker/Podman is installed. Default: auto. """, ) @@ -91,7 +91,7 @@ def main() -> None: Path to the package that you want wheels for. Default: the working directory. Can be a directory inside the working directory, or an sdist. When set to a directory, the working directory is still - considered the 'project' and is copied into the Docker container + considered the 'project' and is copied into the build container on Linux. When set to a tar.gz sdist file, --config-file and --output-dir are relative to the current directory, and other paths are relative to the expanded SDist directory. @@ -208,7 +208,6 @@ def build_in_directory(args: CommandLineArguments) -> None: sys.exit(0) # Add CIBUILDWHEEL environment variable - # This needs to be passed on to the docker container in linux.py os.environ["CIBUILDWHEEL"] = "1" # Python is buffering by default when running on the CI platforms, giving problems interleaving subprocess call output with unflushed calls to 'print' diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 437ff5e8..be87f321 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -59,7 +59,7 @@ class Architecture(Enum): result = {native_architecture} if platform == "linux" and native_architecture == Architecture.x86_64: - # x86_64 machines can run i686 docker containers + # x86_64 machines can run i686 containers result.add(Architecture.i686) if platform == "windows" and native_architecture == Architecture.AMD64: diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index d4eacaef..fe694a7f 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -5,8 +5,8 @@ from pathlib import Path, PurePath, PurePosixPath from typing import Iterator, List, NamedTuple, Set, Tuple from .architecture import Architecture -from .docker_container import OCIContainer from .logger import log +from .oci_container import OCIContainer from .options import Options from .typing import OrderedDict, PathOrStr, assert_never from .util import ( @@ -79,7 +79,7 @@ def get_build_steps( ) -> Iterator[BuildStep]: """ Groups PythonConfigurations into BuildSteps. Each BuildStep represents a - separate Docker container. + separate container instance. """ steps = OrderedDict[Tuple[str, str, str], BuildStep]() @@ -103,18 +103,18 @@ def get_build_steps( yield from steps.values() -def build_on_docker( +def build_in_container( *, options: Options, platform_configs: List[PythonConfiguration], - docker: OCIContainer, + container: OCIContainer, container_project_path: PurePath, container_package_dir: PurePath, ) -> None: container_output_dir = PurePosixPath("/output") - log.step("Copying project into Docker...") - docker.copy_into(Path.cwd(), container_project_path) + log.step("Copying project into container...") + container.copy_into(Path.cwd(), container_project_path) before_all_options_identifier = platform_configs[0].identifier before_all_options = options.build_options(before_all_options_identifier) @@ -122,11 +122,11 @@ def build_on_docker( if before_all_options.before_all: log.step("Running before_all...") - env = docker.get_environment() + env = container.get_environment() env["PATH"] = f'/opt/python/cp38-cp38/bin:{env["PATH"]}' env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" env = before_all_options.environment.as_dictionary( - env, executor=docker.environment_executor + env, executor=container.environment_executor ) before_all_prepared = prepare_command( @@ -134,7 +134,7 @@ def build_on_docker( project=container_project_path, package=container_package_dir, ) - docker.call(["sh", "-c", before_all_prepared], env=env) + container.call(["sh", "-c", before_all_prepared], env=env) built_wheels: List[PurePosixPath] = [] @@ -150,21 +150,21 @@ def build_on_docker( ) container_constraints_file = PurePath("/constraints.txt") - docker.copy_into(constraints_file, container_constraints_file) + container.copy_into(constraints_file, container_constraints_file) dependency_constraint_flags = ["-c", container_constraints_file] log.step("Setting up build environment...") - env = docker.get_environment() + env = container.get_environment() # put this config's python top of the list python_bin = config.path / "bin" env["PATH"] = f'{python_bin}:{env["PATH"]}' - env = build_options.environment.as_dictionary(env, executor=docker.environment_executor) + env = build_options.environment.as_dictionary(env, executor=container.environment_executor) # check config python is still on PATH - which_python = docker.call(["which", "python"], env=env, capture_output=True).strip() + which_python = container.call(["which", "python"], env=env, capture_output=True).strip() if PurePosixPath(which_python) != python_bin / "python": print( "cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", @@ -172,7 +172,7 @@ def build_on_docker( ) sys.exit(1) - which_pip = docker.call(["which", "pip"], env=env, capture_output=True).strip() + which_pip = container.call(["which", "pip"], env=env, capture_output=True).strip() if PurePosixPath(which_pip) != python_bin / "pip": print( "cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", @@ -196,19 +196,19 @@ def build_on_docker( project=container_project_path, package=container_package_dir, ) - docker.call(["sh", "-c", before_build_prepared], env=env) + container.call(["sh", "-c", before_build_prepared], env=env) log.step("Building wheel...") temp_dir = PurePosixPath("/tmp/cibuildwheel") built_wheel_dir = temp_dir / "built_wheel" - docker.call(["rm", "-rf", built_wheel_dir]) - docker.call(["mkdir", "-p", built_wheel_dir]) + container.call(["rm", "-rf", built_wheel_dir]) + container.call(["mkdir", "-p", built_wheel_dir]) verbosity_flags = get_build_verbosity_extra_flags(build_options.build_verbosity) if build_options.build_frontend == "pip": - docker.call( + container.call( [ "python", "-m", @@ -223,7 +223,7 @@ def build_on_docker( ) elif build_options.build_frontend == "build": config_setting = " ".join(verbosity_flags) - docker.call( + container.call( [ "python", "-m", @@ -238,11 +238,11 @@ def build_on_docker( else: assert_never(build_options.build_frontend) - built_wheel = docker.glob(built_wheel_dir, "*.whl")[0] + built_wheel = container.glob(built_wheel_dir, "*.whl")[0] repaired_wheel_dir = temp_dir / "repaired_wheel" - docker.call(["rm", "-rf", repaired_wheel_dir]) - docker.call(["mkdir", "-p", repaired_wheel_dir]) + container.call(["rm", "-rf", repaired_wheel_dir]) + container.call(["mkdir", "-p", repaired_wheel_dir]) if built_wheel.name.endswith("none-any.whl"): raise NonPlatformWheelError() @@ -252,21 +252,23 @@ def build_on_docker( repair_command_prepared = prepare_command( build_options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir ) - docker.call(["sh", "-c", repair_command_prepared], env=env) + container.call(["sh", "-c", repair_command_prepared], env=env) else: - docker.call(["mv", built_wheel, repaired_wheel_dir]) + container.call(["mv", built_wheel, repaired_wheel_dir]) - repaired_wheels = docker.glob(repaired_wheel_dir, "*.whl") + repaired_wheels = container.glob(repaired_wheel_dir, "*.whl") if build_options.test_command and build_options.test_selector(config.identifier): log.step("Testing wheel...") # set up a virtual environment to install and test from, to make sure # there are no dependencies that were pulled in at build time. - docker.call(["pip", "install", "virtualenv", *dependency_constraint_flags], env=env) - venv_dir = PurePath(docker.call(["mktemp", "-d"], capture_output=True).strip()) / "venv" + container.call(["pip", "install", "virtualenv", *dependency_constraint_flags], env=env) + venv_dir = ( + PurePath(container.call(["mktemp", "-d"], capture_output=True).strip()) / "venv" + ) - docker.call(["python", "-m", "virtualenv", "--no-download", venv_dir], env=env) + container.call(["python", "-m", "virtualenv", "--no-download", venv_dir], env=env) virtualenv_env = env.copy() virtualenv_env["PATH"] = f"{venv_dir / 'bin'}:{virtualenv_env['PATH']}" @@ -277,7 +279,7 @@ def build_on_docker( project=container_project_path, package=container_package_dir, ) - docker.call(["sh", "-c", before_test_prepared], env=virtualenv_env) + container.call(["sh", "-c", before_test_prepared], env=virtualenv_env) # Install the wheel we just built # Note: If auditwheel produced two wheels, it's because the earlier produced wheel @@ -286,14 +288,14 @@ def build_on_docker( # different external shared libraries. so it doesn't matter which one we run the tests on. # Let's just pick the first one. wheel_to_test = repaired_wheels[0] - docker.call( + container.call( ["pip", "install", str(wheel_to_test) + build_options.test_extras], env=virtualenv_env, ) # Install any requirements to run the tests if build_options.test_requires: - docker.call(["pip", "install", *build_options.test_requires], env=virtualenv_env) + container.call(["pip", "install", *build_options.test_requires], env=virtualenv_env) # Run the tests from a different directory test_command_prepared = prepare_command( @@ -301,15 +303,15 @@ def build_on_docker( project=container_project_path, package=container_package_dir, ) - docker.call(["sh", "-c", test_command_prepared], cwd="/root", env=virtualenv_env) + container.call(["sh", "-c", test_command_prepared], cwd="/root", env=virtualenv_env) # clean up test environment - docker.call(["rm", "-rf", venv_dir]) + container.call(["rm", "-rf", venv_dir]) # move repaired wheels to output if abi3_wheel is None: - docker.call(["mkdir", "-p", container_output_dir]) - docker.call(["mv", *repaired_wheels, container_output_dir]) + container.call(["mkdir", "-p", container_output_dir]) + container.call(["mv", *repaired_wheels, container_output_dir]) built_wheels.extend( container_output_dir / repaired_wheel.name for repaired_wheel in repaired_wheels ) @@ -318,7 +320,7 @@ def build_on_docker( log.step("Copying wheels back to host...") # copy the output back into the host - docker.copy_out(container_output_dir, options.globals.output_dir) + container.copy_out(container_output_dir, options.globals.output_dir) log.step_end() @@ -358,21 +360,21 @@ def build(options: Options, tmp_path: Path) -> None: # pylint: disable=unused-a for build_step in get_build_steps(options, python_configurations): try: ids_to_build = [x.identifier for x in build_step.platform_configs] - log.step( - f"Starting Docker image {build_step.container_image} for {', '.join(ids_to_build)}..." - ) + log.step(f"Starting container image {build_step.container_image}...") + + print(f"info: This container will host the build for {', '.join(ids_to_build)}...") with OCIContainer( image=build_step.container_image, simulate_32_bit=build_step.platform_tag.endswith("i686"), cwd=container_project_path, engine=options.globals.container_engine, - ) as docker: + ) as container: - build_on_docker( + build_in_container( options=options, platform_configs=build_step.platform_configs, - docker=docker, + container=container, container_project_path=container_project_path, container_package_dir=container_package_dir, ) diff --git a/cibuildwheel/docker_container.py b/cibuildwheel/oci_container.py similarity index 95% rename from cibuildwheel/docker_container.py rename to cibuildwheel/oci_container.py index b910c497..2d79720f 100644 --- a/cibuildwheel/docker_container.py +++ b/cibuildwheel/oci_container.py @@ -56,7 +56,7 @@ class OCIContainer: engine: ContainerEngine = "docker", ): if not image: - raise ValueError("Must have a non-empty docker image to run.") + raise ValueError("Must have a non-empty image to run.") self.image = image self.simulate_32_bit = simulate_32_bit @@ -175,17 +175,19 @@ class OCIContainer: f"cat > {shell_quote(to_path)}", ], stdin=subprocess.PIPE, - ) as docker: - docker.stdin = cast(IO[bytes], docker.stdin) + ) as exec_process: + exec_process.stdin = cast(IO[bytes], exec_process.stdin) with open(from_path, "rb") as from_file: - shutil.copyfileobj(from_file, docker.stdin) + shutil.copyfileobj(from_file, exec_process.stdin) - docker.stdin.close() - docker.wait() + exec_process.stdin.close() + exec_process.wait() - if docker.returncode: - raise subprocess.CalledProcessError(docker.returncode, docker.args, None, None) + if exec_process.returncode: + raise subprocess.CalledProcessError( + exec_process.returncode, exec_process.args, None, None + ) def copy_out(self, from_path: PurePath, to_path: Path) -> None: # note: we assume from_path is a dir diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index df4114e2..8a5e75c3 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -27,8 +27,8 @@ else: from packaging.specifiers import SpecifierSet from .architecture import Architecture -from .docker_container import ContainerEngine from .environment import EnvironmentParseError, ParsedEnvironment, parse_environment +from .oci_container import ContainerEngine from .projectfiles import get_requires_python_str from .typing import PLATFORMS, Literal, PlatformName, TypedDict from .util import ( diff --git a/docs/diagram.md b/docs/diagram.md index d0557b4f..fe542997 100644 --- a/docs/diagram.md +++ b/docs/diagram.md @@ -8,7 +8,7 @@
- Manylinux Docker container + Manylinux container
@@ -76,7 +76,7 @@ steps: [ [ { - label: 'copy project into docker', + label: 'copy project into container', platforms: ['linux'], style: 'block', width: 2, @@ -204,7 +204,7 @@ ], [ { - label: 'Copy wheels out of Docker', + label: 'Copy wheels out of container', platforms: ['linux'], style: 'block', width: 2, diff --git a/docs/faq.md b/docs/faq.md index 66c05618..fbbf4c67 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -4,15 +4,15 @@ title: Tips and tricks ## Tips -### Linux builds on Docker +### Linux builds in containers -Linux wheels are built in the [`manylinux`/`musllinux` docker images](https://github.com/pypa/manylinux) to provide binary compatible wheels on Linux, according to [PEP 600](https://www.python.org/dev/peps/pep-0600/) / [PEP 656](https://www.python.org/dev/peps/pep-0656/). Because of this, when building with `cibuildwheel` on Linux, a few things should be taken into account: +Linux wheels are built in [`manylinux`/`musllinux` containers](https://github.com/pypa/manylinux) to provide binary compatible wheels on Linux, according to [PEP 600](https://www.python.org/dev/peps/pep-0600/) / [PEP 656](https://www.python.org/dev/peps/pep-0656/). Because of this, when building with `cibuildwheel` on Linux, a few things should be taken into account: -- Programs and libraries are not installed on the CI runner host, but rather should be installed inside of the Docker image - using `yum` for `manylinux2010` or `manylinux2014`, `apt-get` for `manylinux_2_24` and `apk` for `musllinux_1_1`, or manually. The same goes for environment variables that are potentially needed to customize the wheel building. +- Programs and libraries are not installed on the CI runner host, but rather should be installed inside the container - using `yum` for `manylinux2010` or `manylinux2014`, `apt-get` for `manylinux_2_24` and `apk` for `musllinux_1_1`, or manually. The same goes for environment variables that are potentially needed to customize the wheel building. - `cibuildwheel` supports this by providing the [`CIBW_ENVIRONMENT`](options.md#environment) and [`CIBW_BEFORE_ALL`](options.md#before-all) options to setup the build environment inside the running Docker image. + `cibuildwheel` supports this by providing the [`CIBW_ENVIRONMENT`](options.md#environment) and [`CIBW_BEFORE_ALL`](options.md#before-all) options to setup the build environment inside the running container. -- The project directory is mounted in the running Docker instance as `/project`, the output directory for the wheels as `/output`. In general, this is handled transparently by `cibuildwheel`. For a more finegrained level of control however, the root of the host file system is mounted as `/host`, allowing for example to access shared files, caches, etc. on the host file system. Note that `/host` is not available on CircleCI due to their Docker policies. +- The project directory is mounted inside the container as `/project`, the output directory for the wheels as `/output`. In general, this is handled transparently by `cibuildwheel`. For a more finegrained level of control however, the root of the host file system is mounted as `/host`, allowing for example to access shared files, caches, etc. on the host file system. Note that `/host` is not available on CircleCI due to their Docker policies. - Alternative Docker images can be specified with the `CIBW_MANYLINUX_*_IMAGE`/`CIBW_MUSLLINUX_*_IMAGE` options to allow for a custom, preconfigured build environment for the Linux builds. See [options](options.md#linux-image) for more details. diff --git a/docs/options.md b/docs/options.md index f72b388a..fbd03796 100644 --- a/docs/options.md +++ b/docs/options.md @@ -117,9 +117,9 @@ matches overriding earlier ones if multiple selectors match. Environment variables always override static configuration. A few of the options below have special handling in overrides. A different -`before-all` will trigger a new docker launch on Linux, and cannot be +`before-all` will trigger a new container to launch on Linux, and cannot be overridden on macOS or Windows. Overriding the image on linux will also -generate new docker launches, one per image. Some commands are not supported; +trigger new containers, one per image. Some commands are not supported; `output-dir`, build/skip/test_skip selectors, and architectures cannot be overridden. @@ -174,7 +174,7 @@ Default: `auto` `auto` will auto-detect platform using environment variables, such as `TRAVIS_OS_NAME`/`APPVEYOR`/`CIRCLECI`. -- For `linux`, you need Docker running, on Linux, macOS, or Windows. +- For `linux`, you need [Docker or Podman](#container-engine) running, on Linux, macOS, or Windows. - For `macos` and `windows`, you need to be running on the respective system, with a working compiler toolchain installed - Xcode Command Line tools for macOS, and MSVC for Windows. This option can also be set using the [command-line option](#command-line) `--platform`. This option is not available in the `pyproject.toml` config. @@ -523,7 +523,7 @@ Choose which build backend to use. Can either be "pip", which will run A list of environment variables to set during the build. Bash syntax should be used, even on Windows. -You must set this variable to pass variables to Linux builds (since they execute in a Docker container). It also works for the other platforms. +You must set this variable to pass variables to Linux builds (since they execute in a container). It also works for the other platforms. You can use `$PATH` syntax to insert other variables, or the `$(pwd)` syntax to insert the output of other shell commands. @@ -637,14 +637,14 @@ To specify more than one environment variable, separate the variable names by sp Shell command to prepare a common part of the project (e.g. build or install libraries which does not depend on the specific version of Python). -This option is very useful for the Linux build, where builds take place in isolated Docker containers managed by cibuildwheel. This command will run inside the container before the wheel builds start. Note, if you're building both `x86_64` and `i686` wheels (the default), your build uses two different Docker images. In that case, this command will execute twice - once per build container. +This option is very useful for the Linux build, where builds take place in isolated containers managed by cibuildwheel. This command will run inside the container before the wheel builds start. Note, if you're building both `x86_64` and `i686` wheels (the default), your build uses two different container images. In that case, this command will execute twice - once per build container. The placeholder `{package}` can be used here; it will be replaced by the path to the package being built by cibuildwheel. On Windows and macOS, the version of Python available inside `CIBW_BEFORE_ALL` is whatever is available on the host machine. On Linux, a modern Python version is available on PATH. This option has special behavior in the overrides section in `pyproject.toml`. -On linux, overriding it triggers a new docker launch. It cannot be overridden +On linux, overriding it triggers a new container launch. It cannot be overridden on macOS and Windows. Platform-specific environment variables also available:
@@ -866,7 +866,7 @@ Platform-specific environment variables are also available:
### `CIBW_MANYLINUX_*_IMAGE`, `CIBW_MUSLLINUX_*_IMAGE` {: #linux-image} -> Specify alternative manylinux / musllinux Docker images +> Specify alternative manylinux / musllinux container images The available options are (default value): @@ -893,9 +893,9 @@ For `CIBW_MUSLLINUX_*_IMAGE`, the value of this option can either be set to `mus If this option is blank, it will fall though to the next available definition (environment variable -> pyproject.toml -> default). -If setting a custom Docker image, you'll need to make sure it can be used in the same way as the official, default Docker images: all necessary Python and pip versions need to be present in `/opt/python/`, and the auditwheel tool needs to be present for cibuildwheel to work. Apart from that, the architecture and relevant shared system libraries need to be compatible to the relevant standard to produce valid manylinux1/manylinux2010/manylinux2014/manylinux_2_24/manylinux_2_28/musllinux_1_1 wheels (see [pypa/manylinux on GitHub](https://github.com/pypa/manylinux), [PEP 513](https://www.python.org/dev/peps/pep-0513/), [PEP 571](https://www.python.org/dev/peps/pep-0571/), [PEP 599](https://www.python.org/dev/peps/pep-0599/), [PEP 600](https://www.python.org/dev/peps/pep-0600/) and [PEP 656](https://www.python.org/dev/peps/pep-0656/) for more details). +If setting a custom image, you'll need to make sure it can be used in the same way as the default images: all necessary Python and pip versions need to be present in `/opt/python/`, and the auditwheel tool needs to be present for cibuildwheel to work. Apart from that, the architecture and relevant shared system libraries need to be compatible to the relevant standard to produce valid manylinux1/manylinux2010/manylinux2014/manylinux_2_24/manylinux_2_28/musllinux_1_1 wheels (see [pypa/manylinux on GitHub](https://github.com/pypa/manylinux), [PEP 513](https://www.python.org/dev/peps/pep-0513/), [PEP 571](https://www.python.org/dev/peps/pep-0571/), [PEP 599](https://www.python.org/dev/peps/pep-0599/), [PEP 600](https://www.python.org/dev/peps/pep-0600/) and [PEP 656](https://www.python.org/dev/peps/pep-0656/) for more details). -Auditwheel detects the version of the manylinux / musllinux standard in the Docker image through the `AUDITWHEEL_PLAT` environment variable, as cibuildwheel has no way of detecting the correct `--plat` command line argument to pass to auditwheel for a custom image. If a Docker image does not correctly set this `AUDITWHEEL_PLAT` environment variable, the `CIBW_ENVIRONMENT` option can be used to do so (e.g., `CIBW_ENVIRONMENT='AUDITWHEEL_PLAT="manylinux2010_$(uname -m)"'`). +Auditwheel detects the version of the manylinux / musllinux standard in the image through the `AUDITWHEEL_PLAT` environment variable, as cibuildwheel has no way of detecting the correct `--plat` command line argument to pass to auditwheel for a custom image. If a custom image does not correctly set this `AUDITWHEEL_PLAT` environment variable, the `CIBW_ENVIRONMENT` option can be used to do so (e.g., `CIBW_ENVIRONMENT='AUDITWHEEL_PLAT="manylinux2010_$(uname -m)"'`). #### Examples diff --git a/test/test_docker_images.py b/test/test_container_images.py similarity index 100% rename from test/test_docker_images.py rename to test/test_container_images.py diff --git a/test/test_manylinuxXXXX_only.py b/test/test_manylinuxXXXX_only.py index 2a80cbb3..935aa592 100644 --- a/test/test_manylinuxXXXX_only.py +++ b/test/test_manylinuxXXXX_only.py @@ -53,7 +53,7 @@ project_with_manylinux_symbols = test_projects.new_c_project( ) def test(manylinux_image, tmp_path): if utils.platform != "linux": - pytest.skip("the docker test is only relevant to the linux build") + pytest.skip("the container image test is only relevant to the linux build") elif platform.machine() not in ["x86_64", "i686"]: if manylinux_image in ["manylinux1", "manylinux2010"]: pytest.skip("manylinux1 and 2010 doesn't exist for non-x86 architectures") diff --git a/unit_test/linux_build_steps_test.py b/unit_test/linux_build_steps_test.py index fd8f1788..36aaebb7 100644 --- a/unit_test/linux_build_steps_test.py +++ b/unit_test/linux_build_steps_test.py @@ -2,8 +2,8 @@ import textwrap from pathlib import Path from pprint import pprint -import cibuildwheel.docker_container import cibuildwheel.linux +import cibuildwheel.oci_container from cibuildwheel.options import Options from .utils import get_default_command_line_arguments @@ -11,7 +11,7 @@ from .utils import get_default_command_line_arguments def test_linux_container_split(tmp_path: Path, monkeypatch): """ - Tests splitting linux builds by docker image and before_all + Tests splitting linux builds by container image and before_all """ args = get_default_command_line_arguments() diff --git a/unit_test/docker_container_test.py b/unit_test/oci_container_test.py similarity index 99% rename from unit_test/docker_container_test.py rename to unit_test/oci_container_test.py index e4252b03..ca629119 100644 --- a/unit_test/docker_container_test.py +++ b/unit_test/oci_container_test.py @@ -9,8 +9,8 @@ from pathlib import Path, PurePath, PurePosixPath import pytest import toml -from cibuildwheel.docker_container import OCIContainer from cibuildwheel.environment import EnvironmentAssignmentBash +from cibuildwheel.oci_container import OCIContainer # Test utilities diff --git a/unit_test/option_prepare_test.py b/unit_test/option_prepare_test.py index 903746d4..10bca432 100644 --- a/unit_test/option_prepare_test.py +++ b/unit_test/option_prepare_test.py @@ -15,7 +15,7 @@ ALL_IDS = {"cp36", "cp37", "cp38", "cp39", "cp310", "pp37", "pp38", "pp39"} @pytest.fixture -def mock_build_docker(monkeypatch): +def mock_build_container(monkeypatch): def fail_on_call(*args, **kwargs): raise RuntimeError("This should never be called") @@ -37,56 +37,58 @@ def mock_build_docker(monkeypatch): monkeypatch.setattr(util, "download", fail_on_call) monkeypatch.setattr("cibuildwheel.linux.OCIContainer", ignore_context_call) - monkeypatch.setattr("cibuildwheel.linux.build_on_docker", mock.Mock(spec=linux.build_on_docker)) + monkeypatch.setattr( + "cibuildwheel.linux.build_in_container", mock.Mock(spec=linux.build_in_container) + ) monkeypatch.setattr("cibuildwheel.util.print_new_wheels", ignore_context_call) -def test_build_default_launches(mock_build_docker, fake_package_dir, monkeypatch): +def test_build_default_launches(mock_build_container, fake_package_dir, monkeypatch): monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--platform=linux"]) main() - build_on_docker = cast(mock.Mock, linux.build_on_docker) + build_in_container = cast(mock.Mock, linux.build_in_container) - assert build_on_docker.call_count == 4 + assert build_in_container.call_count == 4 # In Python 3.8+, this can be simplified to [0].kwargs - kwargs = build_on_docker.call_args_list[0][1] - assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert not kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[0][1] + assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-manylinux_x86_64" for x in ALL_IDS} - kwargs = build_on_docker.call_args_list[1][1] - assert "quay.io/pypa/manylinux2014_i686" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[1][1] + assert "quay.io/pypa/manylinux2014_i686" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-manylinux_i686" for x in ALL_IDS} - kwargs = build_on_docker.call_args_list[2][1] - assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert not kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[2][1] + assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == { f"{x}-musllinux_x86_64" for x in ALL_IDS for x in ALL_IDS if "pp" not in x } - kwargs = build_on_docker.call_args_list[3][1] - assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[3][1] + assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-musllinux_i686" for x in ALL_IDS if "pp" not in x} -def test_build_with_override_launches(mock_build_docker, monkeypatch, tmp_path): +def test_build_with_override_launches(mock_build_container, monkeypatch, tmp_path): pkg_dir = tmp_path / "cibw_package" pkg_dir.mkdir() @@ -113,23 +115,23 @@ before-all = "true" main() - build_on_docker = cast(mock.Mock, linux.build_on_docker) + build_in_container = cast(mock.Mock, linux.build_in_container) - assert build_on_docker.call_count == 6 + assert build_in_container.call_count == 6 - kwargs = build_on_docker.call_args_list[0][1] - assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert not kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[0][1] + assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {"cp36-manylinux_x86_64"} assert kwargs["options"].build_options("cp36-manylinux_x86_64").before_all == "true" - kwargs = build_on_docker.call_args_list[1][1] - assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert not kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[1][1] + assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == { @@ -137,10 +139,10 @@ before-all = "true" } assert kwargs["options"].build_options("cp37-manylinux_x86_64").before_all == "" - kwargs = build_on_docker.call_args_list[2][1] - assert "quay.io/pypa/manylinux_2_24_x86_64" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert not kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[2][1] + assert "quay.io/pypa/manylinux_2_24_x86_64" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == { "cp310-manylinux_x86_64", @@ -149,28 +151,28 @@ before-all = "true" "pp39-manylinux_x86_64", } - kwargs = build_on_docker.call_args_list[3][1] - assert "quay.io/pypa/manylinux2014_i686" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[3][1] + assert "quay.io/pypa/manylinux2014_i686" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-manylinux_i686" for x in ALL_IDS} - kwargs = build_on_docker.call_args_list[4][1] - assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert not kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[4][1] + assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == { f"{x}-musllinux_x86_64" for x in ALL_IDS for x in ALL_IDS if "pp" not in x } - kwargs = build_on_docker.call_args_list[5][1] - assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["docker"]["image"] - assert kwargs["docker"]["cwd"] == PurePosixPath("/project") - assert kwargs["docker"]["simulate_32_bit"] + kwargs = build_in_container.call_args_list[5][1] + assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["container"]["image"] + assert kwargs["container"]["cwd"] == PurePosixPath("/project") + assert kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-musllinux_i686" for x in ALL_IDS if "pp" not in x}