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 <noreply@anthropic.com>

---------

Co-authored-by: Henry Schreiner <henryfs@princeton.edu>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Matthieu Darbois
2026-06-06 23:10:32 -04:00
committed by GitHub
co-authored by Claude Opus 4.8 Henry Schreiner
parent e2f143c327
commit 70975c2153
2 changed files with 25 additions and 3 deletions
+1 -1
View File
@@ -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)
+24 -2
View File
@@ -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")