diff --git a/upath/_chain.py b/upath/_chain.py index 63c7ffc3..83261332 100644 --- a/upath/_chain.py +++ b/upath/_chain.py @@ -216,6 +216,13 @@ def unchain(self, path: str, kwargs: dict[str, Any]) -> list[ChainSegment]: out.append(ChainSegment(None, protocol, kw)) if previous_bit is not None: bit = previous_bit + elif ( + protocol in {"blockcache", "filecache", "simplecache"} + and "target_protocol" in kw + ): + out.append(ChainSegment(None, protocol, kw)) + if previous_bit is not None: + bit = previous_bit else: out.append(ChainSegment(bit, protocol, kw)) previous_bit = bit diff --git a/upath/core.py b/upath/core.py index a94dd3d3..413cbc08 100644 --- a/upath/core.py +++ b/upath/core.py @@ -425,7 +425,7 @@ def __init__( segments = chain_parser.unchain( str_args0, {"protocol": protocol, **storage_options} ) - chain = Chain.from_list(segments) + chain = Chain.from_list(Chain.from_list(segments).to_list()) if len(args) > 1: chain = chain.replace( path=WrappedFileSystemFlavour.from_protocol(protocol).join( @@ -1120,14 +1120,14 @@ def group(self) -> str: def absolute(self) -> Self: if self._relative_base is not None: - return self.cwd().joinpath(str(self)) + return self.cwd().joinpath(self.__vfspath__()) return self def is_absolute(self) -> bool: if self._relative_base is not None: return False else: - return self.parser.isabs(str(self)) + return self.parser.isabs(self.__vfspath__()) def __eq__(self, other: object) -> bool: """UPaths are considered equal if their protocol, path and @@ -1293,7 +1293,8 @@ def root(self) -> str: return self.parser.splitroot(str(self))[1] def __reduce__(self): - args = tuple(self._raw_urlpaths) + # args = tuple(self._raw_urlpaths) + args = (self.__vfspath__(),) kwargs = { "protocol": self._protocol, **self._storage_options, diff --git a/upath/tests/cases.py b/upath/tests/cases.py index 8b6e4fc0..b05a52ab 100644 --- a/upath/tests/cases.py +++ b/upath/tests/cases.py @@ -1,6 +1,5 @@ import os import pickle -import re import stat import sys import warnings @@ -380,12 +379,8 @@ def test_fsspec_compat(self): fs = self.path.fs content = b"a,b,c\n1,2,3\n4,5,6" - def strip_scheme(path): - root = "" if sys.platform.startswith("win") else "/" - return root + re.sub("^[a-z0-9]+:/*", "", str(path)) - upath1 = self.path / "output1.csv" - p1 = strip_scheme(upath1) + p1 = upath1.path upath1.write_bytes(content) assert fs is upath1.fs with fs.open(p1) as f: @@ -394,7 +389,7 @@ def strip_scheme(path): # write with fsspec, read with upath upath2 = self.path / "output2.csv" - p2 = strip_scheme(upath2) + p2 = upath2.path assert fs is upath2.fs with fs.open(p2, "wb") as f: f.write(content)