Skip to content

Commit 4f42ee3

Browse files
authored
fix: raise clear errors when no wheel is produced (#2909)
1 parent f3aa1be commit 4f42ee3

7 files changed

Lines changed: 54 additions & 8 deletions

File tree

‎cibuildwheel/errors.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,19 @@ class AuditCommandFailedError(FatalError):
109109
def __init__(self, message: str) -> None:
110110
super().__init__(message)
111111
self.return_code = 9
112+
113+
114+
class BuildProducedNoWheelError(FatalError):
115+
def __init__(self) -> None:
116+
message = textwrap.dedent(
117+
"""
118+
Build failed because the build frontend completed successfully but
119+
did not produce a wheel.
120+
121+
This usually indicates a problem with your project configuration or
122+
build backend. Check your project configuration, or run cibuildwheel
123+
with CIBW_BUILD_VERBOSITY=1 to view build logs.
124+
"""
125+
)
126+
super().__init__(message)
127+
self.return_code = 10

‎cibuildwheel/platforms/android.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,14 @@ def setup_android_env(
410410
# * a key=value string, without quotes
411411
for i, token in enumerate(shlex.split(env_output)):
412412
if i % 2 == 0:
413-
assert token == "export", token
413+
if token != "export":
414+
msg = f"Unexpected output from android.py env: expected 'export', got {token!r}"
415+
raise errors.FatalError(msg)
414416
else:
415417
key, sep, value = token.partition("=")
416-
assert sep == "=", token
418+
if sep != "=":
419+
msg = f"Unexpected output from android.py env: expected 'key=value', got {token!r}"
420+
raise errors.FatalError(msg)
417421
android_env[key] = value
418422

419423
# localized_vars cleared the CFLAGS and CXXFLAGS in the sysconfigdata, but most

‎cibuildwheel/platforms/ios.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ def build_python_config(config_dict: dict[str, str]) -> dict[str, str]:
9595
matching = [
9696
config for config in macos_python_configs if config["identifier"] == macos_identifier
9797
]
98+
if not matching:
99+
msg = (
100+
f"Internal error: no macOS configuration found matching "
101+
f"{macos_identifier!r}, needed to build the iOS configuration "
102+
f"{config_dict['identifier']!r}. The bundled build-platforms.toml "
103+
f"resources are inconsistent."
104+
)
105+
raise errors.FatalError(msg)
98106
return matching[0]
99107

100108
# Load the platform configuration
@@ -560,7 +568,10 @@ def build(options: Options, tmp_path: Path) -> None:
560568
case _:
561569
assert_never(build_frontend)
562570

563-
built_wheel = next(built_wheel_dir.glob("*.whl"))
571+
try:
572+
built_wheel = next(built_wheel_dir.glob("*.whl"))
573+
except StopIteration:
574+
raise errors.BuildProducedNoWheelError() from None
564575

565576
if built_wheel.name.endswith("none-any.whl"):
566577
raise errors.NonPlatformWheelError()

‎cibuildwheel/platforms/linux.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ def build_in_container(
346346
case _:
347347
assert_never(build_frontend)
348348

349-
built_wheel = container.glob(built_wheel_dir, "*.whl")[0]
349+
try:
350+
built_wheel = container.glob(built_wheel_dir, "*.whl")[0]
351+
except IndexError:
352+
raise errors.BuildProducedNoWheelError() from None
350353

351354
repaired_wheel_dir = temp_dir / "repaired_wheel"
352355
container.call(["rm", "-rf", repaired_wheel_dir])

‎cibuildwheel/platforms/macos.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ def build(options: Options, tmp_path: Path) -> None:
566566
case _:
567567
assert_never(build_frontend)
568568

569-
built_wheel = next(built_wheel_dir.glob("*.whl"))
569+
try:
570+
built_wheel = next(built_wheel_dir.glob("*.whl"))
571+
except StopIteration:
572+
raise errors.BuildProducedNoWheelError() from None
570573

571574
repaired_wheel_dir.mkdir()
572575

‎cibuildwheel/platforms/pyodide.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,10 @@ def build(options: Options, tmp_path: Path) -> None:
451451
*extra_flags,
452452
env=env,
453453
)
454-
built_wheel = next(built_wheel_dir.glob("*.whl"))
454+
try:
455+
built_wheel = next(built_wheel_dir.glob("*.whl"))
456+
except StopIteration:
457+
raise errors.BuildProducedNoWheelError() from None
455458

456459
if built_wheel.name.endswith("none-any.whl"):
457460
raise errors.NonPlatformWheelError()
@@ -471,7 +474,10 @@ def build(options: Options, tmp_path: Path) -> None:
471474
else:
472475
shutil.move(str(built_wheel), repaired_wheel_dir)
473476

474-
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
477+
try:
478+
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
479+
except StopIteration:
480+
raise errors.RepairStepProducedNoWheelError() from None
475481

476482
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
477483
raise errors.AlreadyBuiltWheelError(repaired_wheel.name)

‎cibuildwheel/platforms/windows.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,10 @@ def build(options: Options, tmp_path: Path) -> None:
522522
case _:
523523
assert_never(build_frontend)
524524

525-
built_wheel = next(built_wheel_dir.glob("*.whl"))
525+
try:
526+
built_wheel = next(built_wheel_dir.glob("*.whl"))
527+
except StopIteration:
528+
raise errors.BuildProducedNoWheelError() from None
526529

527530
# repair the wheel
528531
repaired_wheel_dir.mkdir()

0 commit comments

Comments
 (0)