diff --git a/cosmos_framework/utils/easy_io/backends/base_backend.py b/cosmos_framework/utils/easy_io/backends/base_backend.py index 94484bbc..1eb50093 100644 --- a/cosmos_framework/utils/easy_io/backends/base_backend.py +++ b/cosmos_framework/utils/easy_io/backends/base_backend.py @@ -70,7 +70,7 @@ def isfile(self, filepath: Union[str, Path]) -> bool: pass @abstractmethod - def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> str: + def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> Union[str, Path]: pass @abstractmethod diff --git a/cosmos_framework/utils/easy_io/backends/boto3_backend.py b/cosmos_framework/utils/easy_io/backends/boto3_backend.py index 86b1ab0c..ce4ba5f3 100644 --- a/cosmos_framework/utils/easy_io/backends/boto3_backend.py +++ b/cosmos_framework/utils/easy_io/backends/boto3_backend.py @@ -284,7 +284,7 @@ def join_path( self, filepath: Union[str, Path], *filepaths: Union[str, Path], - ) -> str: + ) -> Union[str, Path]: r"""Concatenate all file paths. Join one or more filepath components intelligently. The return value @@ -294,7 +294,7 @@ def join_path( filepath (str or Path): Path to be concatenated. Returns: - str: The result after concatenation. + str or Path: The result after concatenation. Examples: >>> backend = Boto3Backend() diff --git a/cosmos_framework/utils/easy_io/backends/http_backend.py b/cosmos_framework/utils/easy_io/backends/http_backend.py index 32be9086..593c9acd 100644 --- a/cosmos_framework/utils/easy_io/backends/http_backend.py +++ b/cosmos_framework/utils/easy_io/backends/http_backend.py @@ -112,7 +112,7 @@ def isdir(self, filepath: Union[str, Path]) -> bool: def isfile(self, filepath: Union[str, Path]) -> bool: raise NotImplementedError(f"isfile not supported in {self.name}") - def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> str: + def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> Union[str, Path]: raise NotImplementedError(f"join_path not supported in {self.name}") @contextmanager diff --git a/cosmos_framework/utils/easy_io/backends/local_backend.py b/cosmos_framework/utils/easy_io/backends/local_backend.py index 80d05b8c..7599314e 100644 --- a/cosmos_framework/utils/easy_io/backends/local_backend.py +++ b/cosmos_framework/utils/easy_io/backends/local_backend.py @@ -187,7 +187,7 @@ def isfile(self, filepath: Union[str, Path]) -> bool: """ return osp.isfile(filepath) - def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> str: + def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> Union[str, Path]: r"""Concatenate all file paths. Join one or more filepath components intelligently. The return value @@ -197,7 +197,7 @@ def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> filepath (str or Path): Path to be concatenated. Returns: - str: The result of concatenation. + str or Path: The result of concatenation. Returns a Path if any input is a Path. Examples: >>> backend = LocalBackend() @@ -207,8 +207,10 @@ def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> >>> backend.join_path(filepath1, filepath2, filepath3) '/path/of/dir/dir2/path/of/file' """ - # TODO, if filepath or filepaths are Path, should return Path - return osp.join(filepath, *filepaths) + result = osp.join(filepath, *filepaths) + if isinstance(filepath, Path) or any(isinstance(p, Path) for p in filepaths): + return Path(result) + return result @contextmanager def get_local_path( diff --git a/cosmos_framework/utils/easy_io/backends/msc_backend.py b/cosmos_framework/utils/easy_io/backends/msc_backend.py index 83cc56f5..72ac6549 100644 --- a/cosmos_framework/utils/easy_io/backends/msc_backend.py +++ b/cosmos_framework/utils/easy_io/backends/msc_backend.py @@ -554,7 +554,7 @@ def join_path( self, filepath: Union[str, Path], *filepaths: Union[str, Path], - ) -> str: + ) -> Union[str, Path]: r"""Concatenate all file paths. Join one or more filepath components intelligently. The return value @@ -564,7 +564,7 @@ def join_path( filepath (str or Path): Path to be concatenated. Returns: - str: The result after concatenation. + str or Path: The result after concatenation. Examples: >>> backend = MSCBackend() diff --git a/cosmos_framework/utils/easy_io/easy_io.py b/cosmos_framework/utils/easy_io/easy_io.py index 686ae307..19637645 100644 --- a/cosmos_framework/utils/easy_io/easy_io.py +++ b/cosmos_framework/utils/easy_io/easy_io.py @@ -424,7 +424,7 @@ def join_path( backend_key (str, optional): The key to get the backend from register. Returns: - str: The result of concatenation. + str or Path: The result of concatenation. Returns a Path if any input is a Path. Examples: >>> filepath1 = '/path/of/dir1' diff --git a/cosmos_framework/utils/easy_io/file_client.py b/cosmos_framework/utils/easy_io/file_client.py index 650489ff..4a333288 100644 --- a/cosmos_framework/utils/easy_io/file_client.py +++ b/cosmos_framework/utils/easy_io/file_client.py @@ -375,7 +375,7 @@ def isfile(self, filepath: Union[str, Path]) -> bool: """ return self.client.isfile(filepath) - def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> str: + def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> Union[str, Path]: r"""Concatenate all file paths. Join one or more filepath components intelligently. The return value @@ -385,7 +385,7 @@ def join_path(self, filepath: Union[str, Path], *filepaths: Union[str, Path]) -> filepath (str or Path): Path to be concatenated. Returns: - str: The result of concatenation. + str or Path: The result of concatenation. Returns a Path if any input is a Path. """ return self.client.join_path(filepath, *filepaths)