|
15 | 15 |
|
16 | 16 | import os |
17 | 17 | import glob |
18 | | -from pathlib import Path |
| 18 | +import pathlib |
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 = Path(__file__).parent.parent |
| 26 | +core_path = pathlib.Path(__file__).parent.parent.resolve() |
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: |
| 33 | +if grpc_path is not None: |
34 | 34 | # Update ansys-grpc-dpf with latest in proto/dist |
35 | 35 | print("Updating ansys.grpc.dpf") |
36 | | - dist_path = Path(grpc_path) / "proto" / "dist" / "*" |
| 36 | + dist_path = os.path.join(grpc_path, "proto", "dist", "*") |
37 | 37 | print(f"from {dist_path}") |
38 | | - destination = Path(core_path) / "src" |
| 38 | + destination = os.path.join(core_path, "src") |
39 | 39 | print(f"into {destination}") |
40 | | - latest_wheel = max(glob.glob(str(dist_path)), key=os.path.getctime) |
| 40 | + latest_wheel = max(glob.glob(dist_path), 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: |
| 53 | +if gate_path is not None: |
54 | 54 | # Update ansys-dpf-gate |
55 | 55 | print("Updating ansys.dpf.gate generated code") |
56 | | - dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "generated" |
| 56 | + dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys", "dpf", "gate", "generated") |
57 | 57 | print(f"from {dist_path}") |
58 | | - destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "generated" |
| 58 | + destination = os.path.join(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 str(directory)[-5:] == "gate" else [], |
| 64 | + ignore=lambda directory, contents: ["__pycache__"] if directory[-5:] == "gate" else [], |
65 | 65 | ) |
66 | | - |
67 | | - dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "__init__.py" |
| 66 | + dist_path = os.path.join(gate_path, "ansys-dpf-gate", "ansys", "dpf", "gate", "__init__.py") |
68 | 67 | print(f"from {dist_path}") |
69 | | - destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "__init__.py" |
| 68 | + destination = os.path.join(core_path, "src", "ansys", "dpf", "gate", "__init__.py") |
70 | 69 | print(f"into {destination}") |
71 | | - shutil.copy(src=dist_path, dst=destination) |
| 70 | + shutil.copy( |
| 71 | + src=dist_path, |
| 72 | + dst=destination, |
| 73 | + ) |
72 | 74 | print("Done updating ansys.dpf.gate generated code") |
73 | 75 |
|
74 | 76 | # Update ansys-dpf-gatebin |
75 | 77 | print("Updating ansys.dpf.gatebin") |
76 | | - dist_path = Path(gate_path) / "ansys-dpf-gatebin" / "ansys" |
| 78 | + dist_path = os.path.join(gate_path, "ansys-dpf-gatebin", "ansys") |
77 | 79 | print(f"from {dist_path}") |
78 | | - destination = Path(core_path) / "src" / "ansys" |
| 80 | + destination = os.path.join(core_path, "src", "ansys") |
79 | 81 | print(f"into {destination}") |
80 | | - shutil.copytree(src=dist_path, dst=destination, dirs_exist_ok=True) |
| 82 | + shutil.copytree( |
| 83 | + src=dist_path, |
| 84 | + dst=destination, |
| 85 | + dirs_exist_ok=True, |
| 86 | + ) |
81 | 87 | print(f"Done updating ansys.dpf.gatebin for {platform.system()}") |
82 | 88 | else: |
83 | 89 | print( |
|
0 commit comments