Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cloudpathlib/cloudpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def __hash__(self):
def __eq__(self, other: Any):
return repr(self) == repr(other)

def __fspath__(self):
if self.is_file():
self._refresh_cache(force_overwrite_from_cloud=False)
return str(self._local)

# ====================== NOT IMPLEMENTED ======================
# absolute - no cloud equivalent; all cloud paths are absolute already
# as_posix - no cloud equivalent; not needed since we assume url separator
Expand Down Expand Up @@ -277,6 +282,10 @@ def as_uri(self) -> str:
def exists(self) -> bool:
return self.client._exists(self)

@property
def fspath(self) -> str:
return self.__fspath__()
Comment thread
jayqi marked this conversation as resolved.

def glob(self, pattern: str) -> Iterable["CloudPath"]:
# strip cloud prefix from pattern if it is included
if pattern.startswith(self.cloud_prefix):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cloudpath_instantiation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from cloudpathlib import AzureBlobPath, CloudPath, InvalidPrefix, MissingDependencies, S3Path
Expand Down Expand Up @@ -60,3 +62,19 @@ def test_dependencies_not_loaded(rig, monkeypatch):
CloudPath(f"{rig.cloud_prefix}/bucket/dir_0/file0_0.txt")
with pytest.raises(MissingDependencies):
rig.create_cloud_path("bucket/dir_0/file0_0.txt")


def test_is_pathlike(rig):
p = rig.create_cloud_path("bucket")
assert isinstance(p, os.PathLike)


def test_fspath(rig):
p = rig.create_cloud_path("bucket")
os.fspath(p)


def test_os_open(rig):
p = rig.create_cloud_path("bucket/dir_0/file0_0.txt")
with open(p, "r") as f:
assert f.readable()