Skip to content

Commit 8d5feb3

Browse files
committed
Overwrite original wheel in place
1 parent c9210cb commit 8d5feb3

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

bin/cibw_repair_wheel_licenses.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,23 @@ def main(*args: str):
1313
Update license information in wheels after running auditwheel etc.
1414
1515
Usage:
16-
cibw_repair_wheel_licenses.py <dest_dir> <wheel_file> \
16+
cibw_repair_wheel_licenses.py <wheel_file> \
1717
--license MIT --license-file licenses/license_foo_MIT.txt \
1818
--license BSD-3-Clause --license-file licenses/license_bar_BSD-3-Clause.txt \
1919
...
2020
2121
CWD should be at project root (containing pyproject.toml) and license-file
2222
paths must be relative.
2323
24-
The wheel_file argument's basename is the filename but the wheel file
25-
is expected to be found in the dest_dir e.g.:
26-
27-
$ cibw_repair_wheel_licenses.py dist wheels/foo-1.0.whl
28-
29-
means that the wheel is expected to be found at dist/foo-1.0.whl.
30-
31-
This command overwrites the wheel file in place.
24+
The wheel_file argument should be the path to the wheel file to be repaired.
25+
It will be overwritten in place.
3226
"""
3327
parser = argparse.ArgumentParser()
34-
parser.add_argument("dest_dir")
3528
parser.add_argument("wheel_file")
3629
parser.add_argument("--license", action="append", default=[])
3730
parser.add_argument("--license-file", action="append", default=[])
3831

3932
parsed = parser.parse_args(args)
40-
dest_dir = Path(parsed.dest_dir)
4133
wheel_file = Path(parsed.wheel_file)
4234
licenses = parsed.license
4335
license_files = [Path(f) for f in parsed.license_file]
@@ -52,27 +44,26 @@ def main(*args: str):
5244
#
5345
raise ValueError("license-file paths must be relative to project root")
5446

55-
update_licenses_wheel(dest_dir, wheel_file, licenses, license_files)
47+
update_licenses_wheel(wheel_file, licenses, license_files)
5648

5749

5850
def update_licenses_wheel(
59-
dest_dir: Path, wheel_file: Path, licenses: list[str], license_files: list[Path]
51+
wheel_file: Path, licenses: list[str], license_files: list[Path]
6052
):
6153
# foo/bar-1.0-cp310-cp310-linux_x86_64.whl -> bar-1.0
6254
name, version = wheel_file.stem.split('-')[:2]
63-
wheel_path = dest_dir / wheel_file.name
64-
if wheel_path.exists():
65-
print("Found wheel at", wheel_path)
55+
if wheel_file.exists():
56+
print("Found wheel at", wheel_file)
6657
else:
67-
raise ValueError(f"Wheel not found at {wheel_path}")
58+
raise ValueError(f"Wheel not found at {wheel_file}")
6859

6960
base = f"{name}-{version}"
7061

7162
with TemporaryDirectory() as tmpdir:
7263

7364
tmpdir = Path(tmpdir)
7465
print("temp dir:", tmpdir)
75-
run(["wheel", "unpack", "--dest", tmpdir, wheel_path], check=True)
66+
run(["wheel", "unpack", "--dest", tmpdir, wheel_file], check=True)
7667
dist_info = tmpdir / base / f"{base}.dist-info"
7768

7869
print(f"Adding licenses in {dist_info}")
@@ -88,14 +79,16 @@ def update_licenses_wheel(
8879
new_wheel_file = wheels[0]
8980

9081
print(f"Repaired wheel: {new_wheel_file}")
91-
print(f"Copying to {wheel_path}")
92-
copyfile(new_wheel_file, wheel_path)
82+
print(f"Copying back to: {wheel_file}")
83+
copyfile(new_wheel_file, wheel_file)
9384

9485

9586
def update_license_dist_info(
9687
dist_info: Path, licenses: list[str], license_files: list[Path]
9788
):
9889
for license_file in license_files:
90+
if license_file.exists():
91+
raise ValueError(f"license file already present: {license_file}")
9992
makedirs(dist_info / license_file.parent, exist_ok=True)
10093
copyfile(license_file, dist_info / license_file)
10194
print(f"Added license file {license_file}")

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,28 @@ PKG_CONFIG_PATH = "$(pwd)/.local/lib/pkgconfig"
114114
before-all = "bin/cibw_before_all_linux_$(uname -m).sh"
115115
before-build = "pip install wheel auditwheel"
116116
repair-wheel-command = [
117-
"auditwheel repair -w {dest_dir} {wheel}",
118-
"""bin/cibw_repair_wheel_licenses.py {dest_dir} {wheel} \
117+
"""bin/cibw_repair_wheel_licenses.py {wheel} \
119118
--license-file wheels/LICENSE_linux_wheels.txt \
120119
""",
120+
"auditwheel repair -w {dest_dir} {wheel}",
121121
]
122122

123123
[tool.cibuildwheel.macos]
124124
before-all = "bin/cibw_before_all_macosx_$(uname -m).sh"
125125
before-build = "pip install wheel delocate"
126126
repair-wheel-command = [
127-
"delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}",
128-
"""bin/cibw_repair_wheel_licenses.py {dest_dir} {wheel} \
127+
"""bin/cibw_repair_wheel_licenses.py {wheel} \
129128
--license-file wheels/LICENSE_macos_wheels.txt \
130129
""",
130+
"delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}",
131131
]
132132

133133
[tool.cibuildwheel.windows]
134134
before-all = "C:\\msys64\\usr\\bin\\bash bin/cibw_before_all_windows.sh"
135135
before-build = "pip install wheel delvewheel"
136136
repair-wheel-command = [
137-
"delvewheel repair -w {dest_dir} {wheel} --add-path .local/bin",
138-
"""bin/cibw_repair_wheel_licenses.py {dest_dir} {wheel} \
137+
"""bin/cibw_repair_wheel_licenses.py {wheel} \
139138
--license-file wheels/LICENSE_windows_wheels.txt \
140139
""",
140+
"delvewheel repair -w {dest_dir} {wheel} --add-path .local/bin",
141141
]

0 commit comments

Comments
 (0)