Skip to content

Commit da952fa

Browse files
MeenaBytesRajesh Meena
andauthored
Supporting Heterogeneous operating system file path of results file (#2337)
Co-authored-by: Rajesh Meena <[email protected]>
1 parent a850312 commit da952fa

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/ansys/dpf/core/data_sources.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from __future__ import annotations
2626

2727
import os
28-
from pathlib import Path
28+
from pathlib import Path, PurePosixPath, PureWindowsPath
2929
import traceback
3030
from typing import TYPE_CHECKING, Union
3131
import warnings
@@ -159,7 +159,9 @@ def set_result_file_path(
159159
['...tmp...file.rst']
160160
161161
"""
162-
filepath = Path(filepath)
162+
filepath = (
163+
PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath)
164+
)
163165
extension = filepath.suffix
164166
# Handle .res files from CFX
165167
if key == "" and extension == ".res":
@@ -290,7 +292,7 @@ def set_domain_result_file_path(
290292
>>> my_data_sources.set_domain_result_file_path(path='/tmp/file1.rst', key='rst', domain_id=1)
291293
292294
"""
293-
path = Path(path)
295+
path = PurePosixPath(path) if self._server.os == "posix" else PureWindowsPath(path)
294296
if key:
295297
self._api.data_sources_set_domain_result_file_path_with_key_utf8(
296298
self, str(path), key, domain_id
@@ -341,7 +343,9 @@ def add_file_path(
341343
# The filename needs to be a fully qualified file name
342344
# if not os.path.dirname(filepath)
343345

344-
filepath = Path(filepath)
346+
filepath = (
347+
PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath)
348+
)
345349
if not filepath.parent.name:
346350
# append local path
347351
filepath = Path.cwd() / filepath.name
@@ -391,7 +395,9 @@ def add_domain_file_path(
391395
392396
"""
393397
# The filename needs to be a fully qualified file name
394-
filepath = Path(filepath)
398+
filepath = (
399+
PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath)
400+
)
395401
if not filepath.parent.name:
396402
# append local path
397403
filepath = Path.cwd() / filepath.name
@@ -424,7 +430,9 @@ def add_file_path_for_specified_result(
424430
The default is ``""``, in which case the key is found directly.
425431
"""
426432
# The filename needs to be a fully qualified file name
427-
filepath = Path(filepath)
433+
filepath = (
434+
PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath)
435+
)
428436
if not filepath.parent.name:
429437
# append local path
430438
filepath = Path.cwd() / filepath.name

src/ansys/dpf/core/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ def streams_provider(self):
429429
return self._stream_provider
430430

431431
def _set_data_sources(self, var_inp):
432-
from pathlib import Path
432+
from pathlib import PurePath
433433

434434
if isinstance(var_inp, dpf.core.DataSources):
435435
self._data_sources = var_inp
436-
elif isinstance(var_inp, (str, Path)):
436+
elif isinstance(var_inp, (str, PurePath)):
437437
self._data_sources = DataSources(var_inp, server=self._server)
438438
else:
439439
self._data_sources = DataSources(server=self._server)

0 commit comments

Comments
 (0)