|
13 | 13 | or the repo defined by the environment variable "ANSYSDPFCORE_ROOT" if it exists. |
14 | 14 | """ |
15 | 15 |
|
16 | | -import os |
17 | 16 | import glob |
18 | | -import pathlib |
| 17 | +import os |
| 18 | +from pathlib import Path |
19 | 19 | import platform |
20 | 20 | import shutil |
21 | 21 | import zipfile |
22 | 22 |
|
23 | | - |
24 | 23 | grpc_path_key = "DPFDV_ROOT" |
25 | 24 | gate_path_key = "ANSYSDPFPYGATE_ROOT" |
26 | | -core_path = pathlib.Path(__file__).parent.parent.resolve() |
| 25 | +core_path = Path(__file__).parent.parent |
27 | 26 | if "ANSYSDPFCORE_ROOT" in os.environ: |
28 | 27 | core_path = os.environ["ANSYSDPFCORE_ROOT"] |
29 | 28 |
|
30 | 29 | grpc_path = os.getenv(grpc_path_key, None) |
31 | 30 | gate_path = os.getenv(gate_path_key, None) |
32 | 31 |
|
33 | | -if grpc_path is not None: |
| 32 | +if grpc_path: |
34 | 33 | # Update ansys-grpc-dpf with latest in proto/dist |
35 | 34 | print("Updating ansys.grpc.dpf") |
36 | | - dist_path = os.path.join(grpc_path, "proto", "dist", "*") |
| 35 | + dist_path = Path(grpc_path) / "proto" / "dist" |
37 | 36 | print(f"from {dist_path}") |
38 | | - destination = os.path.join(core_path, "src") |
| 37 | + destination = Path(core_path) / "src" |
39 | 38 | print(f"into {destination}") |
40 | | - latest_wheel = max(glob.glob(dist_path), key=os.path.getctime) |
| 39 | + latest_wheel = max(dist_path.glob("*"), key=os.path.getctime) |
41 | 40 | with zipfile.ZipFile(latest_wheel, "r") as wheel: |
42 | 41 | for file in wheel.namelist(): |
43 | 42 | # print(file) |
|
50 | 49 | else: |
51 | 50 | print(f"{grpc_path_key} environment variable is not defined. " "Cannot update ansys-grpc-dpf.") |
52 | 51 |
|
53 | | -if gate_path is not None: |
| 52 | +if gate_path: |
54 | 53 | # Update ansys-dpf-gate |
55 | 54 | print("Updating ansys.dpf.gate generated code") |
56 | | - dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys", "dpf", "gate", "generated") |
| 55 | + dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "generated" |
57 | 56 | print(f"from {dist_path}") |
58 | | - destination = os.path.join(core_path, "src", "ansys", "dpf", "gate", "generated") |
| 57 | + destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "generated" |
59 | 58 | print(f"into {destination}") |
60 | 59 | shutil.copytree( |
61 | 60 | src=dist_path, |
62 | 61 | dst=destination, |
63 | 62 | dirs_exist_ok=True, |
64 | | - ignore=lambda directory, contents: ["__pycache__"] if directory[-5:] == "gate" else [], |
| 63 | + ignore=lambda directory, contents: ["__pycache__"] if str(directory)[-5:] == "gate" else [], |
65 | 64 | ) |
66 | | - dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys", "dpf", "gate", "__init__.py") |
| 65 | + |
| 66 | + dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "__init__.py" |
67 | 67 | print(f"from {dist_path}") |
68 | | - destination = os.path.join(core_path, "src", "ansys", "dpf", "gate", "__init__.py") |
| 68 | + destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "__init__.py" |
69 | 69 | print(f"into {destination}") |
70 | | - shutil.copy( |
71 | | - src=dist_path, |
72 | | - dst=destination, |
73 | | - ) |
| 70 | + shutil.copy(src=dist_path, dst=destination) |
74 | 71 | print("Done updating ansys.dpf.gate generated code") |
75 | 72 |
|
76 | 73 | # Update ansys-dpf-gatebin |
77 | 74 | print("Updating ansys.dpf.gatebin") |
78 | | - dist_path = os.path.join(gate_path, "ansys-dpf-gatebin", "ansys") |
| 75 | + dist_path = Path(gate_path) / "ansys-dpf-gatebin" / "ansys" |
79 | 76 | print(f"from {dist_path}") |
80 | | - destination = os.path.join(core_path, "src", "ansys") |
| 77 | + destination = Path(core_path) / "src" / "ansys" |
81 | 78 | print(f"into {destination}") |
82 | | - shutil.copytree( |
83 | | - src=dist_path, |
84 | | - dst=destination, |
85 | | - dirs_exist_ok=True, |
86 | | - ) |
| 79 | + shutil.copytree(src=dist_path, dst=destination, dirs_exist_ok=True) |
87 | 80 | print(f"Done updating ansys.dpf.gatebin for {platform.system()}") |
88 | 81 | else: |
89 | 82 | print( |
|
0 commit comments