From 70975c215353836ca59d7b6f00dc38bc48782daa Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sun, 7 Jun 2026 05:10:32 +0200 Subject: [PATCH] chore: use ConfigurationError when package_dir is outside cwd (#2898) * chore: use ConfigurationError when package_dir is outside cwd Replace a generic Exception with errors. ConfigurationError when package_dir is not inside the working directory. This makes the error type consistent with the project's error handling and allows the CLI to treat this as a fatal error with the expected exit behavior. * test: merge linux package_dir test into linux_build_steps_test Fold the standalone linux_build_test.py into the existing linux_build_steps_test.py, which already covers the linux platform build orchestration. Reuses the file's existing import boilerplate and module-qualified build() call style. Assisted-by: ClaudeCode:claude-opus-4.8 Co-Authored-By: Claude Opus 4.8 --------- Co-authored-by: Henry Schreiner Co-authored-by: Claude Opus 4.8 --- cibuildwheel/platforms/linux.py | 2 +- unit_test/linux_build_steps_test.py | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/platforms/linux.py b/cibuildwheel/platforms/linux.py index 310355d3..f97f6a6a 100644 --- a/cibuildwheel/platforms/linux.py +++ b/cibuildwheel/platforms/linux.py @@ -493,7 +493,7 @@ def build(options: Options, tmp_path: Path) -> None: abs_package_dir = options.globals.package_dir.resolve() if cwd != abs_package_dir and cwd not in abs_package_dir.parents: msg = "package_dir must be inside the working directory" - raise Exception(msg) + raise errors.ConfigurationError(msg) container_project_path = PurePosixPath("/project") container_package_dir = container_project_path / abs_package_dir.relative_to(cwd) diff --git a/unit_test/linux_build_steps_test.py b/unit_test/linux_build_steps_test.py index 42b17509..b93530be 100644 --- a/unit_test/linux_build_steps_test.py +++ b/unit_test/linux_build_steps_test.py @@ -3,7 +3,10 @@ from __future__ import annotations import textwrap from pprint import pprint +import pytest + import cibuildwheel.platforms.linux +from cibuildwheel.errors import ConfigurationError from cibuildwheel.oci_container import OCIContainerEngineConfig from cibuildwheel.options import CommandLineArguments, Options @@ -11,8 +14,6 @@ TYPE_CHECKING = False if TYPE_CHECKING: from pathlib import Path - import pytest - def test_linux_container_split(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: """ @@ -99,3 +100,24 @@ def test_linux_container_split(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) ] assert before_alls(build_steps[3]) == [""] * 4 assert container_engines(build_steps[3]) == [default_container_engine] * 4 + + +def test_package_dir_outside_working_directory_raises_configuration_error( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +) -> None: + work_dir = tmp_path / "work" + work_dir.mkdir() + package_dir = tmp_path / "package" + package_dir.mkdir() + package_dir.joinpath("pyproject.toml").touch() + + monkeypatch.chdir(work_dir) + + command_line_arguments = CommandLineArguments.defaults() + command_line_arguments.package_dir = package_dir + options = Options(platform="linux", command_line_arguments=command_line_arguments, env={}) + + with pytest.raises( + ConfigurationError, match="package_dir must be inside the working directory" + ): + cibuildwheel.platforms.linux.build(options, tmp_path / "build")