diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index fb51f0a3db0..b8a5a80065c 100644 --- a/src/ansys/dpf/core/data_sources.py +++ b/src/ansys/dpf/core/data_sources.py @@ -25,7 +25,7 @@ from __future__ import annotations import os -from pathlib import Path +from pathlib import Path, PurePosixPath, PureWindowsPath import traceback from typing import TYPE_CHECKING, Union import warnings @@ -159,7 +159,9 @@ def set_result_file_path( ['...tmp...file.rst'] """ - filepath = Path(filepath) + filepath = ( + PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath) + ) extension = filepath.suffix # Handle .res files from CFX if key == "" and extension == ".res": @@ -290,7 +292,7 @@ def set_domain_result_file_path( >>> my_data_sources.set_domain_result_file_path(path='/tmp/file1.rst', key='rst', domain_id=1) """ - path = Path(path) + path = PurePosixPath(path) if self._server.os == "posix" else PureWindowsPath(path) if key: self._api.data_sources_set_domain_result_file_path_with_key_utf8( self, str(path), key, domain_id @@ -341,7 +343,9 @@ def add_file_path( # The filename needs to be a fully qualified file name # if not os.path.dirname(filepath) - filepath = Path(filepath) + filepath = ( + PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath) + ) if not filepath.parent.name: # append local path filepath = Path.cwd() / filepath.name @@ -391,7 +395,9 @@ def add_domain_file_path( """ # The filename needs to be a fully qualified file name - filepath = Path(filepath) + filepath = ( + PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath) + ) if not filepath.parent.name: # append local path filepath = Path.cwd() / filepath.name @@ -424,7 +430,9 @@ def add_file_path_for_specified_result( The default is ``""``, in which case the key is found directly. """ # The filename needs to be a fully qualified file name - filepath = Path(filepath) + filepath = ( + PurePosixPath(filepath) if self._server.os == "posix" else PureWindowsPath(filepath) + ) if not filepath.parent.name: # append local path filepath = Path.cwd() / filepath.name diff --git a/src/ansys/dpf/core/model.py b/src/ansys/dpf/core/model.py index 95ca7709962..0ae5cfbff61 100644 --- a/src/ansys/dpf/core/model.py +++ b/src/ansys/dpf/core/model.py @@ -429,11 +429,11 @@ def streams_provider(self): return self._stream_provider def _set_data_sources(self, var_inp): - from pathlib import Path + from pathlib import PurePath if isinstance(var_inp, dpf.core.DataSources): self._data_sources = var_inp - elif isinstance(var_inp, (str, Path)): + elif isinstance(var_inp, (str, PurePath)): self._data_sources = DataSources(var_inp, server=self._server) else: self._data_sources = DataSources(server=self._server)