|
1 | | -"""Script to update ansys.dpf.gate.generated, ansys.dpf.gatebin and ansys.grpc.dpf. |
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 | | - |
16 | 1 | import os |
17 | 2 | import glob |
18 | | -from pathlib import Path |
19 | | -import platform |
20 | | -import shutil |
21 | | -import zipfile |
| 3 | +from ansys.dpf import core |
| 4 | +import pathlib |
| 5 | +import subprocess |
| 6 | +import sys |
22 | 7 |
|
| 8 | +os.environ["PYVISTA_OFF_SCREEN"] = "true" |
| 9 | +os.environ["MPLBACKEND"] = "Agg" |
23 | 10 |
|
24 | | -grpc_path_key = "DPFDV_ROOT" |
25 | | -gate_path_key = "ANSYSDPFPYGATE_ROOT" |
26 | | -core_path = Path(__file__).parent.parent |
27 | | -if "ANSYSDPFCORE_ROOT" in os.environ: |
28 | | - core_path = os.environ["ANSYSDPFCORE_ROOT"] |
| 11 | +actual_path = pathlib.Path(__file__).parent.absolute() |
| 12 | +print(os.path.join(actual_path, os.path.pardir, "examples")) |
29 | 13 |
|
30 | | -grpc_path = os.getenv(grpc_path_key, None) |
31 | | -gate_path = os.getenv(gate_path_key, None) |
32 | 14 |
|
33 | | -if grpc_path: |
34 | | - # Update ansys-grpc-dpf with latest in proto/dist |
35 | | - print("Updating ansys.grpc.dpf") |
36 | | - dist_path = Path(grpc_path) / "proto" / "dist" / "*" |
37 | | - print(f"from {dist_path}") |
38 | | - destination = Path(core_path) / "src" |
39 | | - print(f"into {destination}") |
40 | | - latest_wheel = max(glob.glob(str(dist_path)), key=os.path.getctime) |
41 | | - with zipfile.ZipFile(latest_wheel, "r") as wheel: |
42 | | - for file in wheel.namelist(): |
43 | | - # print(file) |
44 | | - if file.startswith("ansys/"): |
45 | | - wheel.extract( |
46 | | - file, |
47 | | - path=destination, |
48 | | - ) |
49 | | - print("Done updating ansys.grpc.dpf") |
50 | | -else: |
51 | | - print(f"{grpc_path_key} environment variable is not defined. " "Cannot update ansys-grpc-dpf.") |
| 15 | +list_tests = [ |
| 16 | + os.path.join(actual_path, os.path.pardir, "examples", "00-basic"), |
| 17 | + os.path.join(actual_path, os.path.pardir, "examples", "01-transient_analyses"), |
| 18 | + os.path.join(actual_path, os.path.pardir, "examples", "02-modal_analyses"), |
| 19 | + os.path.join(actual_path, os.path.pardir, "examples", "03-harmonic_analyses"), |
| 20 | + os.path.join(actual_path, os.path.pardir, "examples", "06-plotting", "00-basic_plotting.py"), |
| 21 | + os.path.join( |
| 22 | + actual_path, |
| 23 | + os.path.pardir, |
| 24 | + "examples", |
| 25 | + "06-plotting", |
| 26 | + "05-plot_on_warped_mesh.py", |
| 27 | + ), |
| 28 | + os.path.join( |
| 29 | + actual_path, |
| 30 | + os.path.pardir, |
| 31 | + "examples", |
| 32 | + "07-distributed-post", |
| 33 | + "00-distributed_total_disp.py", |
| 34 | + ), |
| 35 | +] |
52 | 36 |
|
53 | | -if gate_path: |
54 | | - # Update ansys-dpf-gate |
55 | | - print("Updating ansys.dpf.gate generated code") |
56 | | - dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "generated" |
57 | | - print(f"from {dist_path}") |
58 | | - destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "generated" |
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 str(directory)[-5:] == "gate" else [], |
| 37 | +if core.SERVER_CONFIGURATION != core.AvailableServerConfigs.InProcessServer: |
| 38 | + list_tests.append( |
| 39 | + os.path.join( |
| 40 | + actual_path, |
| 41 | + os.path.pardir, |
| 42 | + "examples", |
| 43 | + "08-python-operators", |
| 44 | + "00-wrapping_numpy_capabilities.py", |
| 45 | + ) |
65 | 46 | ) |
66 | 47 |
|
67 | | - dist_path = Path(gate_path) / "ansys-dpf-gate" / "ansys" / "dpf" / "gate" / "__init__.py" |
68 | | - print(f"from {dist_path}") |
69 | | - destination = Path(core_path) / "src" / "ansys" / "dpf" / "gate" / "__init__.py" |
70 | | - print(f"into {destination}") |
71 | | - shutil.copy(src=dist_path, dst=destination) |
72 | | - print("Done updating ansys.dpf.gate generated code") |
73 | | - |
74 | | - # Update ansys-dpf-gatebin |
75 | | - print("Updating ansys.dpf.gatebin") |
76 | | - dist_path = Path(gate_path) / "ansys-dpf-gatebin" / "ansys" |
77 | | - print(f"from {dist_path}") |
78 | | - destination = Path(core_path) / "src" / "ansys" |
79 | | - print(f"into {destination}") |
80 | | - shutil.copytree(src=dist_path, dst=destination, dirs_exist_ok=True) |
81 | | - print(f"Done updating ansys.dpf.gatebin for {platform.system()}") |
82 | | -else: |
83 | | - print( |
84 | | - f"{gate_path_key} environment variable is not defined. " |
85 | | - "Cannot update ansys.dpf.gate or ansys.dpf.gatebin." |
86 | | - ) |
| 48 | +for path in list_tests: |
| 49 | + if os.path.isdir(path): |
| 50 | + for file in glob.iglob(os.path.join(path, "*.py")): |
| 51 | + print("\n--------------------------------------------------") |
| 52 | + print(file) |
| 53 | + try: |
| 54 | + subprocess.check_call([sys.executable, file]) |
| 55 | + except subprocess.CalledProcessError as e: |
| 56 | + sys.stderr.write(str(e.args)) |
| 57 | + if e.returncode != 3221225477: |
| 58 | + raise e |
| 59 | + print("PASS") |
| 60 | + else: |
| 61 | + print("\n--------------------------------------------------") |
| 62 | + print(path) |
| 63 | + try: |
| 64 | + subprocess.check_call([sys.executable, file]) |
| 65 | + except subprocess.CalledProcessError as e: |
| 66 | + sys.stderr.write(str(e.args)) |
| 67 | + if e.returncode != 3221225477: |
| 68 | + raise e |
| 69 | + print("PASS") |
0 commit comments