Skip to content

Commit 9cf6bfe

Browse files
committed
maint: edited multiple files to conform with "PTH" ruff rule
1 parent dc42a72 commit 9cf6bfe

File tree

6 files changed

+52
-76
lines changed

6 files changed

+52
-76
lines changed

.ci/build_wheel.py

Lines changed: 8 additions & 10 deletions
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,12 @@
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}")
43+
build_opts_path = Path(tmpdirname) / "build-opts.cfg"
44+
build_opts_path.write_text(f"[bdist_wheel]\nplat-name={requested_platform}")
4545
os.environ["DIST_EXTRA_CONFIG"] = build_opts_path
4646

4747
# Move the binaries
48-
gatebin_folder_path = os.path.join(
49-
os.path.curdir, os.path.join("src", "ansys", "dpf", "gatebin")
50-
)
48+
gatebin_folder_path = Path() / "src" / "ansys" / "dpf" / "gatebin"
5149
binaries_to_move = []
5250
moved = []
5351
if "win" in requested_platform or "any" == requested_platform:
@@ -60,15 +58,15 @@
6058
binaries_to_move.extend(["_version.py"])
6159

6260
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)
61+
src = gatebin_folder_path / binary_name
62+
dst = Path(tmpdirname) / binary_name
6563
print(f"Moving {src} to {dst}")
6664
shutil.move(src=src, dst=dst)
6765
moved.append([dst, src])
6866

6967
if "any" == requested_platform:
7068
# Also remove the gatebin folder
71-
os.rmdir(gatebin_folder_path)
69+
gatebin_folder_path.rmdir()
7270

7371
# Call the build
7472
if not args.wheelhouse:
@@ -83,7 +81,7 @@
8381

8482
if "any" == requested_platform:
8583
# Recreate the gatebin folder
86-
os.mkdir(gatebin_folder_path)
84+
gatebin_folder_path.mkdir()
8785

8886
# Move binaries back
8987
for move_back in moved:

.ci/code_generation.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
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, "*"))
11+
local_dir = Path(__file__).parent
12+
TARGET_PATH = local_dir.parent / "src" / "ansys" / "dpf" / "core" / "operators"
13+
files = glob.glob(str(TARGET_PATH / "*"))
1414
for f in files:
15-
if Path(f).stem == "specification":
15+
file_path = Path(f)
16+
if file_path.stem == "specification":
1617
continue
17-
if Path(f).name == "build.py":
18+
if file_path.name == "build.py":
1819
continue
19-
if Path(f).name == "operator.mustache":
20+
if file_path.name == "operator.mustache":
2021
continue
2122
try:
22-
if os.path.isdir(f):
23-
shutil.rmtree(f)
23+
if file_path.is_dir():
24+
shutil.rmtree(file_path)
2425
else:
25-
os.remove(f)
26+
file_path.unlink()
2627
except:
2728
pass
2829

.ci/run_examples.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
os.environ["MPLBACKEND"] = "Agg"
1313

1414
actual_path = pathlib.Path(__file__).parent.absolute()
15-
print(os.path.join(actual_path, os.path.pardir, "examples"))
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")):
26+
subdir = pathlib.Path(root) / subdirectory
27+
for file in glob.iglob(str(subdir / "*.py")):
2728
if sys.platform == "linux" and "08-python-operators" in file:
2829
continue
2930
elif "win" in sys.platform and "06-distributed_stress_averaging" in file:

.ci/run_non_regression_examples.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,27 @@
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+
path = pathlib.Path(path)
31+
if path.is_dir():
32+
for file in glob.iglob(str(path / "*.py")):
5133
print("\n--------------------------------------------------")
5234
print(file)
5335
try:

.ci/update_dpf_dependencies.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
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 = pathlib.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 = grpc_path / "proto" / "dist" / "*"
3737
print(f"from {dist_path}")
38-
destination = os.path.join(core_path, "src")
38+
destination = core_path / "src"
3939
print(f"into {destination}")
4040
latest_wheel = max(glob.glob(dist_path), key=os.path.getctime)
4141
with zipfile.ZipFile(latest_wheel, "r") as wheel:
@@ -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 = 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 = 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 = 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 = 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 = gate_path / "ansys-dpf-gatebin" / "ansys"
7977
print(f"from {dist_path}")
80-
destination = os.path.join(core_path, "src", "ansys")
78+
destination = 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(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ select = [
7070
# "F", # pyflakes, see https://beta.ruff.rs/docs/rules/#pyflakes-f
7171
# "I", # isort, see https://beta.ruff.rs/docs/rules/#isort-i
7272
# "N", # pep8-naming, see https://beta.ruff.rs/docs/rules/#pep8-naming-n
73-
# "PTH", # flake9-use-pathlib, https://beta.ruff.rs/docs/rules/#flake8-use-pathlib-pth
73+
"PTH", # flake9-use-pathlib, https://beta.ruff.rs/docs/rules/#flake8-use-pathlib-pth
7474
# "TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
7575
]
7676
ignore = [

0 commit comments

Comments
 (0)