Skip to content

Commit e035e3a

Browse files
authored
Merge pull request #1152 from mayeut/already-built
fix: error out if multiple wheels with the same name are produced
2 parents 6fe0354 + 9ed9e6b commit e035e3a

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

cibuildwheel/linux.py

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .options import Options
1212
from .typing import OrderedDict, PathOrStr, assert_never
1313
from .util import (
14+
AlreadyBuiltWheelError,
1415
BuildSelector,
1516
NonPlatformWheelError,
1617
find_compatible_wheel,
@@ -261,6 +262,10 @@ def build_in_container(
261262

262263
repaired_wheels = container.glob(repaired_wheel_dir, "*.whl")
263264

265+
for repaired_wheel in repaired_wheels:
266+
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
267+
raise AlreadyBuiltWheelError(repaired_wheel.name)
268+
264269
if build_options.test_command and build_options.test_selector(config.identifier):
265270
log.step("Testing wheel...")
266271

cibuildwheel/macos.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .typing import Literal, PathOrStr, assert_never
1919
from .util import (
2020
CIBW_CACHE_PATH,
21+
AlreadyBuiltWheelError,
2122
BuildFrontend,
2223
BuildSelector,
2324
NonPlatformWheelError,
@@ -410,6 +411,9 @@ def build(options: Options, tmp_path: Path) -> None:
410411

411412
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
412413

414+
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
415+
raise AlreadyBuiltWheelError(repaired_wheel.name)
416+
413417
log.step_end()
414418

415419
if build_options.test_command and build_options.test_selector(config.identifier):

cibuildwheel/util.py

+14
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,20 @@ def __init__(self) -> None:
372372
super().__init__(message)
373373

374374

375+
class AlreadyBuiltWheelError(Exception):
376+
def __init__(self, wheel_name: str) -> None:
377+
message = textwrap.dedent(
378+
f"""
379+
cibuildwheel: Build failed because a wheel named {wheel_name} was already generated in the current run.
380+
381+
If you expected another wheel to be generated, check your project configuration, or run
382+
cibuildwheel with CIBW_BUILD_VERBOSITY=1 to view build logs.
383+
"""
384+
)
385+
386+
super().__init__(message)
387+
388+
375389
def strtobool(val: str) -> bool:
376390
return val.lower() in {"y", "yes", "t", "true", "on", "1"}
377391

cibuildwheel/windows.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .typing import PathOrStr, assert_never
1919
from .util import (
2020
CIBW_CACHE_PATH,
21+
AlreadyBuiltWheelError,
2122
BuildFrontend,
2223
BuildSelector,
2324
NonPlatformWheelError,
@@ -367,6 +368,9 @@ def build(options: Options, tmp_path: Path) -> None:
367368

368369
repaired_wheel = next(repaired_wheel_dir.glob("*.whl"))
369370

371+
if repaired_wheel.name in {wheel.name for wheel in built_wheels}:
372+
raise AlreadyBuiltWheelError(repaired_wheel.name)
373+
370374
if build_options.test_command and options.globals.test_selector(config.identifier):
371375
log.step("Testing wheel...")
372376
# set up a virtual environment to install and test from, to make sure

test/test_same_wheel.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import subprocess
2+
from test import test_projects
3+
4+
import pytest
5+
6+
from . import utils
7+
8+
basic_project = test_projects.new_c_project()
9+
basic_project.files[
10+
"repair.py"
11+
] = """
12+
import shutil
13+
import sys
14+
from pathlib import Path
15+
16+
wheel = Path(sys.argv[1])
17+
dest_dir = Path(sys.argv[2])
18+
platform = wheel.stem.split("-")[-1]
19+
name = f"spam-0.1.0-py2-none-{platform}.whl"
20+
dest = dest_dir / name
21+
dest_dir.mkdir(parents=True, exist_ok=True)
22+
if dest.exists():
23+
dest.unlink()
24+
shutil.copy(wheel, dest)
25+
"""
26+
27+
28+
def test(tmp_path, capfd):
29+
# this test checks that a generated wheel name shall be unique in a given cibuildwheel run
30+
project_dir = tmp_path / "project"
31+
basic_project.generate(project_dir)
32+
33+
with pytest.raises(subprocess.CalledProcessError):
34+
utils.cibuildwheel_run(
35+
project_dir,
36+
add_env={
37+
"CIBW_REPAIR_WHEEL_COMMAND": "python repair.py {wheel} {dest_dir}",
38+
},
39+
)
40+
41+
captured = capfd.readouterr()
42+
assert "Build failed because a wheel named" in captured.err

0 commit comments

Comments
 (0)