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