Skip to content

Commit f6aa2ab

Browse files
committed
fix: reverted src .py files
1 parent 8fbf4c5 commit f6aa2ab

File tree

3 files changed

+56
-65
lines changed

3 files changed

+56
-65
lines changed

src/ansys/dpf/core/core.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import logging
3030
import warnings
3131
import weakref
32-
from pathlib import Path
3332

3433
from ansys.dpf.core import errors, misc
3534
from ansys.dpf.core import server as server_module
@@ -430,6 +429,7 @@ def load_library(self, file_path, name="", symbol="LoadOperators", generate_oper
430429
)
431430
if generate_operators:
432431
# TODO: fix code generation upload posix
432+
import os
433433

434434
def __generate_code(TARGET_PATH, filename, name, symbol):
435435
from ansys.dpf.core.dpf_operator import Operator
@@ -444,8 +444,8 @@ def __generate_code(TARGET_PATH, filename, name, symbol):
444444
except Exception as e:
445445
warnings.warn("Unable to generate the python code with error: " + str(e.args))
446446

447-
local_dir = Path(__file__).parent
448-
LOCAL_PATH = local_dir / "operators"
447+
local_dir = os.path.dirname(os.path.abspath(__file__))
448+
LOCAL_PATH = os.path.join(local_dir, "operators")
449449
if not self._server().local_server:
450450
if self._server().os != "posix" or (not self._server().os and os.name != "posix"):
451451
# send local generated code
@@ -761,25 +761,24 @@ def upload_files_in_folder(
761761
new file paths server side
762762
"""
763763
server_paths = []
764-
client_folder_path = Path(client_folder_path)
765-
for root, subdirectories, files in client_folder_path.walk():
764+
for root, subdirectories, files in os.walk(client_folder_path):
766765
for subdirectory in subdirectories:
767-
subdir = root / subdirectory
768-
for filename in subdir.iterdir():
769-
f = subdir / filename
766+
subdir = os.path.join(root, subdirectory)
767+
for filename in os.listdir(subdir):
768+
f = os.path.join(subdir, filename)
770769
server_paths = self._upload_and_get_server_path(
771770
specific_extension,
772-
str(f),
771+
f,
773772
filename,
774773
server_paths,
775774
str(to_server_folder_path),
776775
subdirectory,
777776
)
778777
for file in files:
779-
f = root / file
778+
f = os.path.join(root, file)
780779
server_paths = self._upload_and_get_server_path(
781780
specific_extension,
782-
str(f),
781+
f,
783782
file,
784783
server_paths,
785784
str(to_server_folder_path),
@@ -837,8 +836,7 @@ def upload_file(self, file_path, to_server_file_path):
837836
server_file_path : str
838837
path generated server side
839838
"""
840-
file_path = Path(file_path)
841-
if file_path.stat().st_size == 0:
839+
if os.stat(file_path).st_size == 0:
842840
raise ValueError(file_path + " is empty")
843841
if not self._server().has_client():
844842
txt = """
@@ -870,12 +868,11 @@ def upload_file_in_tmp_folder(self, file_path, new_file_name=None):
870868
server_file_path : str
871869
path generated server side
872870
"""
873-
file_path = Path(file_path)
874871
if new_file_name:
875872
file_name = new_file_name
876873
else:
877-
file_name = Path(file_path).name
878-
if file_path.stat().st_size == 0:
874+
file_name = os.path.basename(file_path)
875+
if os.stat(file_path).st_size == 0:
879876
raise ValueError(file_path + " is empty")
880877
if not self._server().has_client():
881878
txt = """

src/ansys/dpf/core/custom_operator.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import abc
3232
import ctypes
3333
import os
34-
from pathlib import Path
34+
import pathlib
3535
import re
3636
import shutil
3737
import tempfile
@@ -85,23 +85,23 @@ def update_virtual_environment_for_custom_operators(
8585
raise NotImplementedError(
8686
"Updating the dpf-site.zip of a DPF Server is only available when InProcess."
8787
)
88-
current_dpf_site_zip_path = Path(server.ansys_path) / "dpf" / "python" / "dpf-site.zip"
88+
current_dpf_site_zip_path = os.path.join(server.ansys_path, "dpf", "python", "dpf-site.zip")
8989
# Get the path to where we store the original dpf-site.zip
90-
original_dpf_site_zip_path = (
91-
Path(server.ansys_path) / "dpf" / "python" / "original" / "dpf-site.zip"
90+
original_dpf_site_zip_path = os.path.join(
91+
server.ansys_path, "dpf", "python", "original", "dpf-site.zip"
9292
)
9393
# Restore the original dpf-site.zip
9494
if restore_original:
95-
if original_dpf_site_zip_path.exists():
95+
if os.path.exists(original_dpf_site_zip_path):
9696
shutil.move(src=original_dpf_site_zip_path, dst=current_dpf_site_zip_path)
97-
original_dpf_site_zip_path.parent.rmdir()
97+
os.rmdir(os.path.dirname(original_dpf_site_zip_path))
9898
else:
9999
warnings.warn("No original dpf-site.zip found. Current is most likely the original.")
100100
else:
101101
# Store original dpf-site.zip for this DPF Server if no original is stored
102-
if not original_dpf_site_zip_path.parent.exists():
103-
original_dpf_site_zip_path.parent.mkdir()
104-
if not original_dpf_site_zip_path.exists():
102+
if not os.path.exists(os.path.dirname(original_dpf_site_zip_path)):
103+
os.mkdir(os.path.dirname(original_dpf_site_zip_path))
104+
if not os.path.exists(original_dpf_site_zip_path):
105105
shutil.move(src=current_dpf_site_zip_path, dst=original_dpf_site_zip_path)
106106
# Get the current paths to site_packages
107107
import site
@@ -111,60 +111,59 @@ def update_virtual_environment_for_custom_operators(
111111
# Get the first one targeting an actual site-packages folder
112112
for path_to_site_packages in paths_to_current_site_packages:
113113
if path_to_site_packages[-13:] == "site-packages":
114-
current_site_packages_path = Path(path_to_site_packages)
114+
current_site_packages_path = pathlib.Path(path_to_site_packages)
115115
break
116116
if current_site_packages_path is None:
117117
warnings.warn("Could not find a currently loaded site-packages folder to update from.")
118118
return
119119
# If an ansys.dpf.core.path file exists, then the installation is editable
120-
search_path = current_site_packages_path
120+
search_path = pathlib.Path(current_site_packages_path)
121121
potential_editable = list(search_path.rglob("__editable__.ansys_dpf_core-*.pth"))
122122
if potential_editable:
123123
path_file = potential_editable[0]
124124
else: # Keep for older setuptools versions
125-
path_file = current_site_packages_path / "ansys.dpf.core.pth"
126-
if path_file.exists():
125+
path_file = os.path.join(current_site_packages_path, "ansys.dpf.core.pth")
126+
if os.path.exists(path_file):
127127
# Treat editable installation of ansys-dpf-core
128-
with path_file.open("r") as f:
128+
with open(path_file, "r") as f:
129129
current_site_packages_path = f.readline().strip()
130130
with tempfile.TemporaryDirectory() as tmpdir:
131-
tmpdir = Path(tmpdir)
132-
ansys_dir = tmpdir / "ansys_dpf_core"
133-
ansys_dir.mkdir()
134-
ansys_dir.joinpath("ansys").mkdir()
135-
ansys_dir.joinpath("ansys", "dpf").mkdir()
136-
ansys_dir.joinpath("ansys", "grpc").mkdir()
131+
os.mkdir(os.path.join(tmpdir, "ansys_dpf_core"))
132+
ansys_dir = os.path.join(tmpdir, "ansys_dpf_core")
133+
os.mkdir(os.path.join(ansys_dir, "ansys"))
134+
os.mkdir(os.path.join(ansys_dir, "ansys", "dpf"))
135+
os.mkdir(os.path.join(ansys_dir, "ansys", "grpc"))
137136
shutil.copytree(
138-
src=current_site_packages_path / "ansys" / "dpf" / "core",
139-
dst=ansys_dir / "ansys" / "dpf" / "core",
137+
src=os.path.join(current_site_packages_path, "ansys", "dpf", "core"),
138+
dst=os.path.join(ansys_dir, "ansys", "dpf", "core"),
140139
ignore=lambda directory, contents: ["__pycache__", "result_files"],
141140
)
142141
shutil.copytree(
143-
src=current_site_packages_path / "ansys" / "dpf" / "gate",
144-
dst=ansys_dir / "ansys" / "dpf" / "gate",
142+
src=os.path.join(current_site_packages_path, "ansys", "dpf", "gate"),
143+
dst=os.path.join(ansys_dir, "ansys", "dpf", "gate"),
145144
ignore=lambda directory, contents: ["__pycache__"],
146145
)
147146
shutil.copytree(
148-
src=current_site_packages_path / "ansys" / "grpc" / "dpf",
149-
dst=ansys_dir / "ansys" / "grpc" / "dpf",
147+
src=os.path.join(current_site_packages_path, "ansys", "grpc", "dpf"),
148+
dst=os.path.join(ansys_dir, "ansys", "grpc", "dpf"),
150149
ignore=lambda directory, contents: ["__pycache__"],
151150
)
152151
# Find the .dist_info folder
153152
pattern = re.compile(r"^ansys_dpf_core\S*")
154-
for p in current_site_packages_path.iterdir():
153+
for p in pathlib.Path(current_site_packages_path).iterdir():
155154
if p.is_dir():
156155
# print(p.stem)
157156
if re.search(pattern, p.stem):
158157
dist_info_path = p
159158
break
160159
shutil.copytree(
161160
src=dist_info_path,
162-
dst=ansys_dir / dist_info_path.name,
161+
dst=os.path.join(ansys_dir, dist_info_path.name),
163162
)
164163
# Zip the files as dpf-site.zip
165-
base_name = tmpdir / "ansys_dpf_core_zip"
164+
base_name = os.path.join(tmpdir, "ansys_dpf_core_zip")
166165
base_dir = "."
167-
root_dir = tmpdir / "ansys_dpf_core" # OK
166+
root_dir = os.path.join(tmpdir, "ansys_dpf_core") # OK
168167
shutil.make_archive(
169168
base_name=base_name, root_dir=root_dir, base_dir=base_dir, format="zip"
170169
)

src/ansys/dpf/core/data_sources.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"""
2929

3030
import os
31-
from pathlib import Path
3231
import warnings
3332
import traceback
3433
from typing import Union
@@ -143,7 +142,7 @@ def set_result_file_path(self, filepath, key=""):
143142
['/tmp/file.rst']
144143
145144
"""
146-
extension = Path(filepath).suffix
145+
extension = os.path.splitext(filepath)[1]
147146
# Handle .res files from CFX
148147
if key == "" and extension == ".res":
149148
key = "cas"
@@ -163,7 +162,7 @@ def set_result_file_path(self, filepath, key=""):
163162
def guess_result_key(filepath: str) -> str:
164163
"""Guess result key for files without a file extension."""
165164
result_keys = ["d3plot", "binout"]
166-
base_name = Path(filepath).name
165+
base_name = os.path.basename(filepath)
167166
# Handle files without extension
168167
for result_key in result_keys:
169168
if result_key in base_name:
@@ -173,13 +172,14 @@ def guess_result_key(filepath: str) -> str:
173172
@staticmethod
174173
def guess_second_key(filepath: str) -> str:
175174
"""For files with an h5 or cff extension, look for another extension."""
176-
177-
# These files usually end with .cas.h5 or .dat.h5
178175
accepted = ["cas", "dat"]
179-
new_split = Path(filepath).suffixes
176+
without_ext = os.path.splitext(filepath)[0]
177+
new_split = os.path.splitext(without_ext)
180178
new_key = ""
181-
if new_split[0] in accepted:
182-
new_key = new_split[0]
179+
if len(new_split) > 1:
180+
key = new_split[1][1:]
181+
if key in accepted:
182+
new_key = key
183183
return new_key
184184

185185
def set_domain_result_file_path(
@@ -241,12 +241,9 @@ def add_file_path(self, filepath, key="", is_domain: bool = False, domain_id=0):
241241
242242
"""
243243
# The filename needs to be a fully qualified file name
244-
# if not os.path.dirname(filepath)
245-
246-
filepath = Path(filepath)
247-
if not filepath.parent.name:
244+
if not os.path.dirname(filepath):
248245
# append local path
249-
filepath = Path.cwd() / filepath.name
246+
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
250247
if is_domain:
251248
if key == "":
252249
raise NotImplementedError("A key must be given when using is_domain=True.")
@@ -283,10 +280,9 @@ def add_domain_file_path(self, filepath, key, domain_id):
283280
284281
"""
285282
# The filename needs to be a fully qualified file name
286-
filepath = Path(filepath)
287-
if not filepath.parent.name:
283+
if not os.path.dirname(filepath):
288284
# append local path
289-
filepath = Path.cwd() / filepath.name
285+
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
290286
self._api.data_sources_add_domain_file_path_with_key_utf8(
291287
self, str(filepath), key, domain_id
292288
)
@@ -311,10 +307,9 @@ def add_file_path_for_specified_result(self, filepath, key="", result_key=""):
311307
The default is ``""``, in which case the key is found directly.
312308
"""
313309
# The filename needs to be a fully qualified file name
314-
filepath = Path(filepath)
315-
if not filepath.parent.name:
310+
if not os.path.dirname(filepath):
316311
# append local path
317-
filepath = Path.cwd() / filepath.name
312+
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
318313

319314
self._api.data_sources_add_file_path_for_specified_result_utf8(
320315
self, str(filepath), key, result_key

0 commit comments

Comments
 (0)