Skip to content

Commit ed2b6e8

Browse files
committed
Merge branch 'master' into feat/migration-from-autodoc-to-autoapi
2 parents d16becb + af30b32 commit ed2b6e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1772
-447
lines changed

.ci/build_wheel.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import argparse
55
import subprocess
6+
from pathlib import Path
67
import os
78
import sys
89
import shutil
@@ -39,15 +40,13 @@
3940
print("Created temporary directory: ", tmpdirname)
4041

4142
# Create the temporary build-opts.cfg
42-
build_opts_path = os.path.join(tmpdirname, "build-opts.cfg")
43-
with open(build_opts_path, "w") as build_opts_file:
44-
build_opts_file.write(f"[bdist_wheel]\nplat-name={requested_platform}")
45-
os.environ["DIST_EXTRA_CONFIG"] = build_opts_path
43+
build_opts_path = Path(tmpdirname) / "build-opts.cfg"
44+
45+
build_opts_path.write_text(f"[bdist_wheel]\nplat-name={requested_platform}", encoding="utf-8")
46+
os.environ["DIST_EXTRA_CONFIG"] = str(build_opts_path)
4647

4748
# Move the binaries
48-
gatebin_folder_path = os.path.join(
49-
os.path.curdir, os.path.join("src", "ansys", "dpf", "gatebin")
50-
)
49+
gatebin_folder_path = Path.cwd() / "src" / "ansys" / "dpf" / "gatebin"
5150
binaries_to_move = []
5251
moved = []
5352
if "win" in requested_platform or "any" == requested_platform:
@@ -60,15 +59,15 @@
6059
binaries_to_move.extend(["_version.py"])
6160

6261
for binary_name in binaries_to_move:
63-
src = os.path.join(gatebin_folder_path, binary_name)
64-
dst = os.path.join(tmpdirname, binary_name)
62+
src = gatebin_folder_path / binary_name
63+
dst = Path(tmpdirname) / binary_name
6564
print(f"Moving {src} to {dst}")
6665
shutil.move(src=src, dst=dst)
6766
moved.append([dst, src])
6867

6968
if "any" == requested_platform:
7069
# Also remove the gatebin folder
71-
os.rmdir(gatebin_folder_path)
70+
gatebin_folder_path.rmdir()
7271

7372
# Call the build
7473
if not args.wheelhouse:
@@ -83,7 +82,7 @@
8382

8483
if "any" == requested_platform:
8584
# Recreate the gatebin folder
86-
os.mkdir(gatebin_folder_path)
85+
gatebin_folder_path.mkdir()
8786

8887
# Move binaries back
8988
for move_back in moved:

.ci/code_generation.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
import shutil
99

1010

11-
local_dir = os.path.dirname(os.path.abspath(__file__))
12-
TARGET_PATH = os.path.join(local_dir, os.pardir, "src", "ansys", "dpf", "core", "operators")
13-
files = glob.glob(os.path.join(TARGET_PATH, "*"))
14-
for f in files:
15-
if Path(f).stem == "specification":
11+
local_dir = Path(__file__).parent
12+
TARGET_PATH = local_dir.parent / "src" / "ansys" / "dpf" / "core" / "operators"
13+
files = TARGET_PATH.glob("*")
14+
for file_path in files:
15+
if file_path.stem == "specification":
1616
continue
17-
if Path(f).name == "build.py":
17+
if file_path.name == "build.py":
1818
continue
19-
if Path(f).name == "operator.mustache":
19+
if file_path.name == "operator.mustache":
2020
continue
2121
try:
22-
if os.path.isdir(f):
23-
shutil.rmtree(f)
22+
if file_path.is_dir():
23+
shutil.rmtree(file_path)
2424
else:
25-
os.remove(f)
25+
file_path.unlink()
2626
except:
2727
pass
2828

.ci/run_examples.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import glob
3-
import pathlib
3+
from pathlib import Path
44
import subprocess
55
import sys
66

@@ -11,22 +11,23 @@
1111
os.environ["PYVISTA_OFF_SCREEN"] = "true"
1212
os.environ["MPLBACKEND"] = "Agg"
1313

14-
actual_path = pathlib.Path(__file__).parent.absolute()
15-
print(os.path.join(actual_path, os.path.pardir, "examples"))
14+
actual_path = Path(__file__).parent.absolute()
15+
examples_path = actual_path.parent / "examples"
16+
print(examples_path)
1617

1718
# Get the DPF server version
1819
server = dpf.server.get_or_create_server(None)
1920
server_version = server.version
2021
server.shutdown()
2122
print(f"Server version: {server_version}")
2223

23-
for root, subdirectories, files in os.walk(os.path.join(actual_path, os.path.pardir, "examples")):
24+
for root, subdirectories, files in os.walk(examples_path):
2425
for subdirectory in subdirectories:
25-
subdir = os.path.join(root, subdirectory)
26-
for file in glob.iglob(os.path.join(subdir, "*.py")):
27-
if sys.platform == "linux" and "08-python-operators" in file:
26+
subdir = Path(root) / subdirectory
27+
for file in subdir.glob("*.py"):
28+
if sys.platform == "linux" and "08-python-operators" in str(file):
2829
continue
29-
elif "win" in sys.platform and "06-distributed_stress_averaging" in file:
30+
elif "win" in sys.platform and "06-distributed_stress_averaging" in str(file):
3031
# Currently very unstable in the GH CI
3132
continue
3233
print("\n--------------------------------------------------")
@@ -36,7 +37,7 @@
3637
print(f"Example skipped as it requires DPF {minimum_version_str}.", flush=True)
3738
continue
3839
try:
39-
out = subprocess.check_output([sys.executable, file])
40+
out = subprocess.check_output([sys.executable, str(file)])
4041
except subprocess.CalledProcessError as e:
4142
sys.stderr.write(str(e.args))
4243
if e.returncode != 3221225477:

.ci/run_non_regression_examples.py

+14-33
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,30 @@
99
os.environ["MPLBACKEND"] = "Agg"
1010

1111
actual_path = pathlib.Path(__file__).parent.absolute()
12-
print(os.path.join(actual_path, os.path.pardir, "examples"))
12+
examples_path = actual_path.parent / "examples"
13+
print(examples_path)
1314

1415

1516
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-
),
17+
examples_path / "00-basic",
18+
examples_path / "01-transient_analyses",
19+
examples_path / "02-modal_analyses",
20+
examples_path / "03-harmonic_analyses",
21+
examples_path / "06-plotting" / "00-basic_plotting.py",
22+
examples_path / "06-plotting" / "05-plot_on_warped_mesh.py",
23+
examples_path / "07-distributed-post" / "00-distributed_total_disp.py",
3524
]
3625

3726
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-
)
46-
)
27+
list_tests.append(examples_path / "08-python-operators" / "00-wrapping_numpy_capabilities.py")
4728

4829
for path in list_tests:
49-
if os.path.isdir(path):
50-
for file in glob.iglob(os.path.join(path, "*.py")):
30+
if path.is_dir():
31+
for file in path.glob("*.py"):
5132
print("\n--------------------------------------------------")
5233
print(file)
5334
try:
54-
subprocess.check_call([sys.executable, file])
35+
subprocess.check_call([sys.executable, str(file)])
5536
except subprocess.CalledProcessError as e:
5637
sys.stderr.write(str(e.args))
5738
if e.returncode != 3221225477:
@@ -61,7 +42,7 @@
6142
print("\n--------------------------------------------------")
6243
print(path)
6344
try:
64-
subprocess.check_call([sys.executable, file])
45+
subprocess.check_call([sys.executable, str(file)])
6546
except subprocess.CalledProcessError as e:
6647
sys.stderr.write(str(e.args))
6748
if e.returncode != 3221225477:

.ci/update_dpf_dependencies.py

+17-23
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@
1515

1616
import os
1717
import glob
18-
import pathlib
18+
from pathlib import Path
1919
import platform
2020
import shutil
2121
import zipfile
2222

2323

2424
grpc_path_key = "DPFDV_ROOT"
2525
gate_path_key = "ANSYSDPFPYGATE_ROOT"
26-
core_path = pathlib.Path(__file__).parent.parent.resolve()
26+
core_path = Path(__file__).parent.parent
2727
if "ANSYSDPFCORE_ROOT" in os.environ:
2828
core_path = os.environ["ANSYSDPFCORE_ROOT"]
2929

3030
grpc_path = os.getenv(grpc_path_key, None)
3131
gate_path = os.getenv(gate_path_key, None)
3232

33-
if grpc_path is not None:
33+
if grpc_path:
3434
# Update ansys-grpc-dpf with latest in proto/dist
3535
print("Updating ansys.grpc.dpf")
36-
dist_path = os.path.join(grpc_path, "proto", "dist", "*")
36+
dist_path = Path(grpc_path) / "proto" / "dist"
3737
print(f"from {dist_path}")
38-
destination = os.path.join(core_path, "src")
38+
destination = Path(core_path) / "src"
3939
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)
4141
with zipfile.ZipFile(latest_wheel, "r") as wheel:
4242
for file in wheel.namelist():
4343
# print(file)
@@ -50,40 +50,34 @@
5050
else:
5151
print(f"{grpc_path_key} environment variable is not defined. " "Cannot update ansys-grpc-dpf.")
5252

53-
if gate_path is not None:
53+
if gate_path:
5454
# Update ansys-dpf-gate
5555
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"
5757
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"
5959
print(f"into {destination}")
6060
shutil.copytree(
6161
src=dist_path,
6262
dst=destination,
6363
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 [],
6565
)
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"
6768
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"
6970
print(f"into {destination}")
70-
shutil.copy(
71-
src=dist_path,
72-
dst=destination,
73-
)
71+
shutil.copy(src=dist_path, dst=destination)
7472
print("Done updating ansys.dpf.gate generated code")
7573

7674
# Update ansys-dpf-gatebin
7775
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"
7977
print(f"from {dist_path}")
80-
destination = os.path.join(core_path, "src", "ansys")
78+
destination = Path(core_path) / "src" / "ansys"
8179
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)
8781
print(f"Done updating ansys.dpf.gatebin for {platform.system()}")
8882
else:
8983
print(

.github/workflows/update_operators.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
git status
124124
125125
- name: "Create Pull Request"
126-
uses: peter-evans/create-pull-request@v4
126+
uses: peter-evans/create-pull-request@v7
127127
with:
128128
delete-branch: true
129129
add-paths: |

doc/source/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
ignored_pattern += f"|{example_name}"
6363
ignored_pattern += "|11-server_types.py"
6464
ignored_pattern += "|06-distributed_stress_averaging.py"
65-
ignored_pattern += "|02-python_operators_with_dependencies.py"
6665
ignored_pattern += r")"
6766

6867
# Autoapi ignore pattern

examples/05-file-IO/00-hdf5_double_float_comparison.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# Import the ``dpf-core`` module and its examples files, and then create a
3737
# temporary directory.
3838

39-
import os
39+
from pathlib import Path
4040

4141
from ansys.dpf import core as dpf
4242
from ansys.dpf.core import examples
@@ -78,8 +78,8 @@
7878
# Define a temporary folder for outputs
7979
tmpdir = dpf.core.make_tmp_dir_server(dpf.SERVER)
8080
files = [
81-
dpf.path_utilities.join(tmpdir, "dpf_float.h5"),
82-
dpf.path_utilities.join(tmpdir, "dpf_double.h5"),
81+
Path(dpf.path_utilities.join(tmpdir, "dpf_float.h5")),
82+
Path(dpf.path_utilities.join(tmpdir, "dpf_double.h5")),
8383
]
8484
###############################################################################
8585
# Export with simple precision.
@@ -98,8 +98,8 @@
9898
# Download the resulting .h5 files if necessary
9999

100100
if not dpf.SERVER.local_server:
101-
float_file_path = os.path.join(os.getcwd(), "dpf_float.h5")
102-
double_file_path = os.path.join(os.getcwd(), "dpf_double.h5")
101+
float_file_path = Path.cwd() / "dpf_float.h5"
102+
double_file_path = Path.cwd() / "dpf_double.h5"
103103
dpf.download_file(files[0], float_file_path)
104104
dpf.download_file(files[1], double_file_path)
105105
else:
@@ -109,8 +109,8 @@
109109

110110
###############################################################################
111111
# Compare simple precision versus double precision.
112-
float_precision = os.stat(float_file_path).st_size
113-
double_precision = os.stat(double_file_path).st_size
112+
float_precision = float_file_path.stat().st_size
113+
double_precision = double_file_path.stat().st_size
114114
print(
115115
f"size with float precision: {float_precision}\n"
116116
f"size with double precision: {double_precision}"

examples/05-file-IO/04-basic-load-file.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@
5858
# ~~~~~~~~~~~~~
5959
# Export the fields container in the CSV format:
6060

61-
import os
61+
from pathlib import Path
6262

6363
csv_file_name = "simple_bar_fc.csv"
6464
# Define an output path for the resulting .csv file
6565
if not dpf.SERVER.local_server:
6666
# Define it server-side if using a remote server
6767
tmp_dir_path = dpf.core.make_tmp_dir_server(dpf.SERVER)
68-
server_file_path = dpf.path_utilities.join(tmp_dir_path, csv_file_name)
68+
server_file_path = Path(dpf.path_utilities.join(tmp_dir_path, csv_file_name))
6969
else:
70-
server_file_path = os.path.join(os.getcwd(), csv_file_name)
70+
server_file_path = Path.cwd() / csv_file_name
7171

7272
# Perform the export to csv on the server side
7373
export_csv_operator = dpf.operators.serialization.field_to_csv()
@@ -81,7 +81,7 @@
8181
# Download the file ``simple_bar_fc.csv``:
8282

8383
if not dpf.SERVER.local_server:
84-
downloaded_client_file_path = os.path.join(os.getcwd(), "simple_bar_fc_downloaded.csv")
84+
downloaded_client_file_path = Path.cwd() / "simple_bar_fc_downloaded.csv"
8585
dpf.download_file(server_file_path, downloaded_client_file_path)
8686
else:
8787
downloaded_client_file_path = server_file_path
@@ -98,7 +98,7 @@
9898
mesh.plot(server_fc_out)
9999

100100
# Remove file to avoid polluting.
101-
os.remove(downloaded_client_file_path)
101+
downloaded_client_file_path.unlink()
102102

103103
###############################################################################
104104
# Make operations over the fields container

0 commit comments

Comments
 (0)