|
| 1 | +# This script generates the different versions of the ansys-dpf-core wheels based on a given input. |
| 2 | +# Input can be one of ["any", "win", "manylinux1", "manylinux_2_17"] |
| 3 | + |
| 4 | +import argparse |
| 5 | +import pathlib |
| 6 | +import subprocess |
| 7 | +import os |
| 8 | +import sys |
| 9 | +import shutil |
| 10 | +import tempfile |
| 11 | + |
| 12 | + |
| 13 | +supported_platforms = { |
| 14 | + "any": "any", |
| 15 | + "win": "win_amd64", |
| 16 | + "manylinux1": "manylinux1_x86_64", |
| 17 | + "manylinux_2_17": "manylinux_2_17_x86_64" |
| 18 | +} |
| 19 | + |
| 20 | +argParser = argparse.ArgumentParser() |
| 21 | +argParser.add_argument("-p", "--platform", help="platform") |
| 22 | +argParser.add_argument("-w", "--wheelhouse", help="platform", action='store_true') |
| 23 | + |
| 24 | +args = argParser.parse_args() |
| 25 | + |
| 26 | +if args.platform not in supported_platforms: |
| 27 | + raise ValueError(f"Platform {args.platform} is not supported. " |
| 28 | + f"Supported platforms are: {list(supported_platforms.keys())}") |
| 29 | +else: |
| 30 | + requested_platform = supported_platforms[args.platform] |
| 31 | +print(requested_platform) |
| 32 | + |
| 33 | +# Move binaries out of the source depending on platform requested |
| 34 | +# any: move all binaries out before building |
| 35 | +# win: move .so binaries out before building |
| 36 | +# lin: move .dll binaries out before building |
| 37 | +with tempfile.TemporaryDirectory() as tmpdirname: |
| 38 | + print('Created temporary directory: ', tmpdirname) |
| 39 | + |
| 40 | + # Create the temporary build-opts.cfg |
| 41 | + build_opts_path = os.path.join(tmpdirname, "build-opts.cfg") |
| 42 | + with open(build_opts_path, "w") as build_opts_file: |
| 43 | + build_opts_file.write(f"[bdist_wheel]\nplat-name={requested_platform}") |
| 44 | + os.environ["DIST_EXTRA_CONFIG"] = build_opts_path |
| 45 | + |
| 46 | + # Move the binaries |
| 47 | + gatebin_folder_path = os.path.join( |
| 48 | + os.path.curdir, |
| 49 | + os.path.join("src", "ansys", "dpf", "gatebin") |
| 50 | + ) |
| 51 | + binaries_to_move = [] |
| 52 | + moved = [] |
| 53 | + if "win" in requested_platform or "any" == requested_platform: |
| 54 | + # Move linux binaries |
| 55 | + binaries_to_move.extend(["libAns.Dpf.GrpcClient.so", "libDPFClientAPI.so"]) |
| 56 | + if "linux" in requested_platform or "any" == requested_platform: |
| 57 | + # Move windows binaries |
| 58 | + binaries_to_move.extend(["Ans.Dpf.GrpcClient.dll", "DPFClientAPI.dll"]) |
| 59 | + if "any" == requested_platform: |
| 60 | + binaries_to_move.extend(["_version.py"]) |
| 61 | + |
| 62 | + for binary_name in binaries_to_move: |
| 63 | + src = os.path.join(gatebin_folder_path, binary_name) |
| 64 | + dst = os.path.join(tmpdirname, binary_name) |
| 65 | + print(f"Moving {src} to {dst}") |
| 66 | + shutil.move(src=src, dst=dst) |
| 67 | + moved.append([dst, src]) |
| 68 | + |
| 69 | + if "any" == requested_platform: |
| 70 | + # Also remove the gatebin folder |
| 71 | + os.rmdir(gatebin_folder_path) |
| 72 | + |
| 73 | + # Call the build |
| 74 | + if not args.wheelhouse: |
| 75 | + cmd = [sys.executable, "-m", "build", "--wheel"] |
| 76 | + else: |
| 77 | + cmd = [sys.executable, "-m", "pip", "wheel", "-w", "dist", "."] |
| 78 | + try: |
| 79 | + subprocess.run(cmd, capture_output=False, text=True) |
| 80 | + print("Done building the wheel.") |
| 81 | + except Exception as e: |
| 82 | + print(f"Build failed with error: {e}") |
| 83 | + |
| 84 | + if "any" == requested_platform: |
| 85 | + # Recreate the gatebin folder |
| 86 | + os.mkdir(gatebin_folder_path) |
| 87 | + |
| 88 | + # Move binaries back |
| 89 | + for move_back in moved: |
| 90 | + print(f"Moving back {move_back[0]} to {move_back[1]}") |
| 91 | + shutil.move(src=move_back[0], dst=move_back[1]) |
| 92 | + print("Binaries moved back.") |
| 93 | + |
| 94 | + print(f"Done building {requested_platform} wheel for ansys-dpf-core!") |
0 commit comments