Skip to content

Commit ce5f5cd

Browse files
committed
Add repair_wheel.py script, similar to cmake
1 parent c0a32a3 commit ce5f5cd

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

scripts/repair_wheel.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import argparse
2+
import shutil
3+
import subprocess
4+
import sys
5+
import tempfile
6+
from pathlib import Path
7+
8+
from convert_to_generic_platform_wheel import convert_to_generic_platform_wheel
9+
10+
11+
def main():
12+
if sys.platform.startswith("linux"):
13+
os_ = "linux"
14+
elif sys.platform == "darwin":
15+
os_ = "macos"
16+
elif sys.platform == "win32":
17+
os_ = "windows"
18+
else:
19+
raise NotImplementedError(f"sys.platform '{sys.platform}' is not supported yet.")
20+
21+
p = argparse.ArgumentParser(description="Convert wheel to be independent of python implementation and ABI")
22+
p.set_defaults(prog=Path(sys.argv[0]).name)
23+
p.add_argument("WHEEL_FILE", help="Path to wheel file.")
24+
p.add_argument(
25+
"-w",
26+
"--wheel-dir",
27+
dest="WHEEL_DIR",
28+
help=('Directory to store delocated wheels (default: "wheelhouse/")'),
29+
default="wheelhouse/",
30+
)
31+
32+
args = p.parse_args()
33+
34+
file = Path(args.WHEEL_FILE).resolve(strict=True)
35+
wheelhouse = Path(args.WHEEL_DIR).resolve()
36+
wheelhouse.mkdir(parents=True, exist_ok=True)
37+
38+
with tempfile.TemporaryDirectory() as tmpdir_:
39+
tmpdir = Path(tmpdir_)
40+
# use the platform specific repair tool first
41+
if os_ == "linux":
42+
subprocess.run(["auditwheel", "repair", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE)
43+
elif os_ == "macos":
44+
subprocess.run(
45+
["delocate-wheel", "--require-archs", "x86_64", "-w", str(tmpdir), str(file)],
46+
check=True,
47+
stdout=subprocess.PIPE,
48+
)
49+
elif os_ == "windows":
50+
# no specific tool, just copy
51+
shutil.copyfile(file, tmpdir / file.name)
52+
files = list(tmpdir.glob("*.whl"))
53+
assert len(files) == 1, files
54+
file = files[0]
55+
56+
# make this a py2.py3 wheel
57+
convert_to_generic_platform_wheel(
58+
str(file),
59+
out_dir=str(wheelhouse),
60+
py2_py3=True,
61+
)
62+
63+
64+
if __name__ == "__main__":
65+
main()

0 commit comments

Comments
 (0)