|
| 1 | +"""Script to update ansys-dpf-gate, ansys-dpf-gatebin and ansys-grpc-dpf based on repositories |
| 2 | +
|
| 3 | +This script should only be used to quickly test changes to any of these dependencies. |
| 4 | +Actual commit of updated code should not occur. |
| 5 | +The GitHub pipelines take care of the actual update in ansys-dpf-core. |
| 6 | +
|
| 7 | +Define environment variables to know where to get the code from: |
| 8 | +- "DPFDV_ROOT" defines the DPF repo where ansys-grpc-dpf resides. |
| 9 | + Will unzip the latest wheel built in DPF/proto/dist/. |
| 10 | +- "ANSYSDPFPYGATE_ROOT" defines where the ansys-dpf-pygate repository resides. |
| 11 | +
|
| 12 | +It will update the current repo |
| 13 | +or the repo defined by the environment variable "ANSYSDPFCORE_ROOT" if it exists. |
| 14 | +""" |
| 15 | +import os |
| 16 | +import glob |
| 17 | +import pathlib |
| 18 | +import platform |
| 19 | +import shutil |
| 20 | +import zipfile |
| 21 | + |
| 22 | + |
| 23 | +grpc_path_key = "DPFDV_ROOT" |
| 24 | +gate_path_key = "ANSYSDPFPYGATE_ROOT" |
| 25 | +core_path = pathlib.Path(__file__).parent.parent.resolve() |
| 26 | +if "ANSYSDPFCORE_ROOT" in os.environ: |
| 27 | + core_path = os.environ["ANSYSDPFCORE_ROOT"] |
| 28 | + |
| 29 | +grpc_path = os.getenv(grpc_path_key, None) |
| 30 | +gate_path = os.getenv(gate_path_key, None) |
| 31 | + |
| 32 | +if grpc_path is not None: |
| 33 | + # Update ansys-grpc-dpf with latest in proto/dist |
| 34 | + print("Updating ansys.grpc.dpf") |
| 35 | + dist_path = os.path.join(grpc_path, "proto", "dist", "*") |
| 36 | + print(f"from {dist_path}") |
| 37 | + destination = os.path.join(core_path, "src") |
| 38 | + print(f"into {destination}") |
| 39 | + latest_wheel = max(glob.glob(dist_path), key=os.path.getctime) |
| 40 | + with zipfile.ZipFile(latest_wheel, 'r') as wheel: |
| 41 | + for file in wheel.namelist(): |
| 42 | + # print(file) |
| 43 | + if file.startswith('ansys/'): |
| 44 | + wheel.extract( |
| 45 | + file, |
| 46 | + path=destination, |
| 47 | + ) |
| 48 | + print("Done updating ansys-grpc-dpf") |
| 49 | +else: |
| 50 | + print(f"{grpc_path_key} environment variable is not defined. " |
| 51 | + "Cannot update ansys-grpc-dpf.") |
| 52 | + |
| 53 | +if gate_path is not None: |
| 54 | + # Update ansys-dpf-gate |
| 55 | + print("Updating ansys.dpf.gate") |
| 56 | + dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys") |
| 57 | + print(f"from {dist_path}") |
| 58 | + destination = os.path.join(core_path, "src", "ansys") |
| 59 | + print(f"into {destination}") |
| 60 | + shutil.copytree( |
| 61 | + src=dist_path, |
| 62 | + dst=destination, |
| 63 | + dirs_exist_ok=True, |
| 64 | + ignore=lambda directory, contents: ["__pycache__"] if directory[-5:] == "gate" else [], |
| 65 | + ) |
| 66 | + print("Done updating ansys-dpf-gate") |
| 67 | + |
| 68 | + # Update ansys-dpf-gatebin |
| 69 | + print("Updating ansys.dpf.gatebin") |
| 70 | + dist_path = os.path.join(gate_path, "ansys-dpf-gatebin", "ansys") |
| 71 | + print(f"from {dist_path}") |
| 72 | + destination = os.path.join(core_path, "src", "ansys") |
| 73 | + print(f"into {destination}") |
| 74 | + shutil.copytree( |
| 75 | + src=dist_path, |
| 76 | + dst=destination, |
| 77 | + dirs_exist_ok=True, |
| 78 | + ) |
| 79 | + print(f"Done updating ansys-dpf-gatebin for {platform.system()}") |
| 80 | +else: |
| 81 | + print(f"{gate_path_key} environment variable is not defined. " |
| 82 | + "Cannot update ansys-dpf-gate or ansys-dpf-gatebin.") |
0 commit comments