Skip to content

Commit 9e18458

Browse files
committed
doc: modified another src file
1 parent e2f0a65 commit 9e18458

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/ansys/dpf/core/data_sources.py

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

3030
import os
31+
from pathlib import Path
3132
import warnings
3233
import traceback
3334
from typing import Union
@@ -142,7 +143,7 @@ def set_result_file_path(self, filepath, key=""):
142143
['/tmp/file.rst']
143144
144145
"""
145-
extension = os.path.splitext(filepath)[1]
146+
extension = Path(filepath).suffix
146147
# Handle .res files from CFX
147148
if key == "" and extension == ".res":
148149
key = "cas"
@@ -162,7 +163,7 @@ def set_result_file_path(self, filepath, key=""):
162163
def guess_result_key(filepath: str) -> str:
163164
"""Guess result key for files without a file extension."""
164165
result_keys = ["d3plot", "binout"]
165-
base_name = os.path.basename(filepath)
166+
base_name = Path(filepath).name
166167
# Handle files without extension
167168
for result_key in result_keys:
168169
if result_key in base_name:
@@ -172,14 +173,13 @@ def guess_result_key(filepath: str) -> str:
172173
@staticmethod
173174
def guess_second_key(filepath: str) -> str:
174175
"""For files with an h5 or cff extension, look for another extension."""
176+
177+
# These files usually end with .cas.h5 or .dat.h5
175178
accepted = ["cas", "dat"]
176-
without_ext = os.path.splitext(filepath)[0]
177-
new_split = os.path.splitext(without_ext)
179+
new_split = Path(filepath).suffixes
178180
new_key = ""
179-
if len(new_split) > 1:
180-
key = new_split[1][1:]
181-
if key in accepted:
182-
new_key = key
181+
if new_split[0].strip(".") in accepted:
182+
new_key = new_split[0].strip(".")
183183
return new_key
184184

185185
def set_domain_result_file_path(
@@ -241,9 +241,12 @@ 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):
244+
# if not os.path.dirname(filepath)
245+
246+
filepath = Path(filepath)
247+
if not filepath.parent.name:
245248
# append local path
246-
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
249+
filepath = Path.cwd() / filepath.name
247250
if is_domain:
248251
if key == "":
249252
raise NotImplementedError("A key must be given when using is_domain=True.")
@@ -280,9 +283,10 @@ def add_domain_file_path(self, filepath, key, domain_id):
280283
281284
"""
282285
# The filename needs to be a fully qualified file name
283-
if not os.path.dirname(filepath):
286+
filepath = Path(filepath)
287+
if not filepath.parent.name:
284288
# append local path
285-
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
289+
filepath = Path.cwd() / filepath.name
286290
self._api.data_sources_add_domain_file_path_with_key_utf8(
287291
self, str(filepath), key, domain_id
288292
)
@@ -307,9 +311,10 @@ def add_file_path_for_specified_result(self, filepath, key="", result_key=""):
307311
The default is ``""``, in which case the key is found directly.
308312
"""
309313
# The filename needs to be a fully qualified file name
310-
if not os.path.dirname(filepath):
314+
filepath = Path(filepath)
315+
if not filepath.parent.name:
311316
# append local path
312-
filepath = os.path.join(os.getcwd(), os.path.basename(filepath))
317+
filepath = Path.cwd() / filepath.name
313318

314319
self._api.data_sources_add_file_path_for_specified_result_utf8(
315320
self, str(filepath), key, result_key

0 commit comments

Comments
 (0)