Skip to content

Commit a4d2405

Browse files
authored
chore: move AlreadyBuiltWheelError & NonPlatformWheelError to errors.py (#1920)
1 parent 7e5a838 commit a4d2405

File tree

8 files changed

+45
-49
lines changed

8 files changed

+45
-49
lines changed

cibuildwheel/errors.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
semantically clear and unique.
55
"""
66

7+
import textwrap
8+
79

810
class FatalError(BaseException):
911
"""
@@ -25,3 +27,34 @@ class NothingToDoError(FatalError):
2527

2628
class DeprecationError(FatalError):
2729
return_code = 4
30+
31+
32+
class NonPlatformWheelError(FatalError):
33+
def __init__(self) -> None:
34+
message = textwrap.dedent(
35+
"""
36+
Build failed because a pure Python wheel was generated.
37+
38+
If you intend to build a pure-Python wheel, you don't need cibuildwheel - use
39+
`pip wheel -w DEST_DIR .` instead.
40+
41+
If you expected a platform wheel, check your project configuration, or run
42+
cibuildwheel with CIBW_BUILD_VERBOSITY=1 to view build logs.
43+
"""
44+
)
45+
super().__init__(message)
46+
self.return_code = 5
47+
48+
49+
class AlreadyBuiltWheelError(FatalError):
50+
def __init__(self, wheel_name: str) -> None:
51+
message = textwrap.dedent(
52+
f"""
53+
Build failed because a wheel named {wheel_name} was already generated in the current run.
54+
55+
If you expected another wheel to be generated, check your project configuration, or run
56+
cibuildwheel with CIBW_BUILD_VERBOSITY=1 to view build logs.
57+
"""
58+
)
59+
super().__init__(message)
60+
self.return_code = 6

cibuildwheel/linux.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
from .options import BuildOptions, Options
1919
from .typing import PathOrStr
2020
from .util import (
21-
AlreadyBuiltWheelError,
2221
BuildFrontendConfig,
2322
BuildSelector,
24-
NonPlatformWheelError,
2523
find_compatible_wheel,
2624
get_build_verbosity_extra_flags,
2725
prepare_command,
@@ -306,7 +304,7 @@ def build_in_container(
306304
container.call(["mkdir", "-p", repaired_wheel_dir])
307305

308306
if built_wheel.name.endswith("none-any.whl"):
309-
raise NonPlatformWheelError()
307+
raise errors.NonPlatformWheelError()
310308

311309
if build_options.repair_command:
312310
log.step("Repairing wheel...")
@@ -321,7 +319,7 @@ def build_in_container(
321319

322320
for repaired_wheel in repaired_wheels:
323321
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
324-
raise AlreadyBuiltWheelError(repaired_wheel.name)
322+
raise errors.AlreadyBuiltWheelError(repaired_wheel.name)
325323

326324
if build_options.test_command and build_options.test_selector(config.identifier):
327325
log.step("Testing wheel...")

cibuildwheel/macos.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
from .typing import PathOrStr
2626
from .util import (
2727
CIBW_CACHE_PATH,
28-
AlreadyBuiltWheelError,
2928
BuildFrontendConfig,
3029
BuildFrontendName,
3130
BuildSelector,
32-
NonPlatformWheelError,
3331
call,
3432
combine_constraints,
3533
detect_ci_provider,
@@ -525,7 +523,7 @@ def build(options: Options, tmp_path: Path) -> None:
525523
repaired_wheel_dir.mkdir()
526524

527525
if built_wheel.name.endswith("none-any.whl"):
528-
raise NonPlatformWheelError()
526+
raise errors.NonPlatformWheelError()
529527

530528
if build_options.repair_command:
531529
log.step("Repairing wheel...")
@@ -550,7 +548,7 @@ def build(options: Options, tmp_path: Path) -> None:
550548
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
551549

552550
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
553-
raise AlreadyBuiltWheelError(repaired_wheel.name)
551+
raise errors.AlreadyBuiltWheelError(repaired_wheel.name)
554552

555553
log.step_end()
556554

cibuildwheel/pyodide.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
from .typing import PathOrStr
1818
from .util import (
1919
CIBW_CACHE_PATH,
20-
AlreadyBuiltWheelError,
2120
BuildFrontendConfig,
2221
BuildSelector,
23-
NonPlatformWheelError,
2422
call,
2523
combine_constraints,
2624
download,
@@ -299,7 +297,7 @@ def build(options: Options, tmp_path: Path) -> None:
299297
built_wheel = next(built_wheel_dir.glob("*.whl"))
300298

301299
if built_wheel.name.endswith("none-any.whl"):
302-
raise NonPlatformWheelError()
300+
raise errors.NonPlatformWheelError()
303301

304302
if build_options.repair_command:
305303
log.step("Repairing wheel...")
@@ -316,7 +314,7 @@ def build(options: Options, tmp_path: Path) -> None:
316314
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
317315

318316
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
319-
raise AlreadyBuiltWheelError(repaired_wheel.name)
317+
raise errors.AlreadyBuiltWheelError(repaired_wheel.name)
320318

321319
if build_options.test_command and build_options.test_selector(config.identifier):
322320
log.step("Testing wheel...")

cibuildwheel/util.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -462,37 +462,6 @@ def options_summary(self) -> str | dict[str, str]:
462462
return {"name": self.name, "args": repr(self.args)}
463463

464464

465-
class NonPlatformWheelError(Exception):
466-
def __init__(self) -> None:
467-
message = textwrap.dedent(
468-
"""
469-
cibuildwheel: Build failed because a pure Python wheel was generated.
470-
471-
If you intend to build a pure-Python wheel, you don't need cibuildwheel - use
472-
`pip wheel -w DEST_DIR .` instead.
473-
474-
If you expected a platform wheel, check your project configuration, or run
475-
cibuildwheel with CIBW_BUILD_VERBOSITY=1 to view build logs.
476-
"""
477-
)
478-
479-
super().__init__(message)
480-
481-
482-
class AlreadyBuiltWheelError(Exception):
483-
def __init__(self, wheel_name: str) -> None:
484-
message = textwrap.dedent(
485-
f"""
486-
cibuildwheel: Build failed because a wheel named {wheel_name} was already generated in the current run.
487-
488-
If you expected another wheel to be generated, check your project configuration, or run
489-
cibuildwheel with CIBW_BUILD_VERBOSITY=1 to view build logs.
490-
"""
491-
)
492-
493-
super().__init__(message)
494-
495-
496465
def strtobool(val: str) -> bool:
497466
return val.lower() in {"y", "yes", "t", "true", "on", "1"}
498467

cibuildwheel/windows.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
from .typing import PathOrStr
2323
from .util import (
2424
CIBW_CACHE_PATH,
25-
AlreadyBuiltWheelError,
2625
BuildFrontendConfig,
2726
BuildFrontendName,
2827
BuildSelector,
29-
NonPlatformWheelError,
3028
call,
3129
combine_constraints,
3230
download,
@@ -462,7 +460,7 @@ def build(options: Options, tmp_path: Path) -> None:
462460
repaired_wheel_dir.mkdir()
463461

464462
if built_wheel.name.endswith("none-any.whl"):
465-
raise NonPlatformWheelError()
463+
raise errors.NonPlatformWheelError()
466464

467465
if build_options.repair_command:
468466
log.step("Repairing wheel...")
@@ -478,7 +476,7 @@ def build(options: Options, tmp_path: Path) -> None:
478476
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
479477

480478
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
481-
raise AlreadyBuiltWheelError(repaired_wheel.name)
479+
raise errors.AlreadyBuiltWheelError(repaired_wheel.name)
482480

483481
test_selected = options.globals.test_selector(config.identifier)
484482
if test_selected and config.arch == "ARM64" != platform_module.machine():

test/test_custom_repair_wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test(tmp_path, capfd):
3838
else:
3939
expectation = does_not_raise()
4040

41-
with expectation:
41+
with expectation as exc_info:
4242
result = utils.cibuildwheel_run(
4343
project_dir,
4444
add_env={
@@ -49,6 +49,7 @@ def test(tmp_path, capfd):
4949
captured = capfd.readouterr()
5050
if num_builds > 1:
5151
assert "Build failed because a wheel named" in captured.err
52+
assert exc_info.value.returncode == 6
5253
else:
5354
# We only produced one wheel (currently Pyodide)
5455
# check that it has the right name

test/test_pure_wheel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ def test(tmp_path, capfd):
3131
project_dir = tmp_path / "project"
3232
pure_python_project.generate(project_dir)
3333

34-
with pytest.raises(subprocess.CalledProcessError):
34+
with pytest.raises(subprocess.CalledProcessError) as exc_info:
3535
print("produced wheels:", utils.cibuildwheel_run(project_dir))
3636

3737
captured = capfd.readouterr()
3838
print("out", captured.out)
3939
print("err", captured.err)
40+
assert exc_info.value.returncode == 5
4041
assert "Build failed because a pure Python wheel was generated" in captured.err

0 commit comments

Comments
 (0)