Skip to content

Commit d93f71d

Browse files
groutrmartindurant
andauthored
Fixes for _un_chain (#1736)
--------- Co-authored-by: Martin Durant <[email protected]>
1 parent 97a2168 commit d93f71d

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

fsspec/core.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,19 @@ def open_files(
329329

330330

331331
def _un_chain(path, kwargs):
332-
x = re.compile(".*[^a-z]+.*") # test for non protocol-like single word
333-
bits = (
334-
[p if "://" in p or x.match(p) else p + "://" for p in path.split("::")]
335-
if "::" in path
336-
else [path]
337-
)
332+
# Avoid a circular import
333+
from fsspec.implementations.cached import CachingFileSystem
334+
335+
if "::" in path:
336+
x = re.compile(".*[^a-z]+.*") # test for non protocol-like single word
337+
bits = []
338+
for p in path.split("::"):
339+
if "://" in p or x.match(p):
340+
bits.append(p)
341+
else:
342+
bits.append(p + "://")
343+
else:
344+
bits = [path]
338345
# [[url, protocol, kwargs], ...]
339346
out = []
340347
previous_bit = None
@@ -351,10 +358,7 @@ def _un_chain(path, kwargs):
351358
**kws,
352359
)
353360
bit = cls._strip_protocol(bit)
354-
if (
355-
protocol in {"blockcache", "filecache", "simplecache"}
356-
and "target_protocol" not in kw
357-
):
361+
if "target_protocol" not in kw and issubclass(cls, CachingFileSystem):
358362
bit = previous_bit
359363
out.append((bit, protocol, kw))
360364
previous_bit = bit

fsspec/implementations/tests/test_cached.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_blockcache_workflow(ftp_writable, tmp_path, force_save_pickle):
267267
assert f.read(5) == b"test\n"
268268

269269

270-
@pytest.mark.parametrize("impl", ["filecache", "blockcache"])
270+
@pytest.mark.parametrize("impl", ["filecache", "blockcache", "cached"])
271271
def test_workflow(ftp_writable, impl):
272272
host, port, user, pw = ftp_writable
273273
fs = FTPFileSystem(host, port, user, pw)
@@ -295,7 +295,7 @@ def test_workflow(ftp_writable, impl):
295295
) # new value, because we overwrote the cached location
296296

297297

298-
@pytest.mark.parametrize("impl", ["simplecache", "blockcache"])
298+
@pytest.mark.parametrize("impl", ["simplecache", "blockcache", "cached"])
299299
def test_glob(ftp_writable, impl):
300300
host, port, user, pw = ftp_writable
301301
fs = FTPFileSystem(host, port, user, pw)
@@ -622,7 +622,7 @@ def open_raise(*_, **__):
622622
assert "Cache save failed due to interpreter shutdown" in caplog.text
623623

624624

625-
@pytest.mark.parametrize("impl", ["filecache", "simplecache", "blockcache"])
625+
@pytest.mark.parametrize("impl", ["filecache", "simplecache", "blockcache", "cached"])
626626
def test_local_filecache_creates_dir_if_needed(impl):
627627
import tempfile
628628

@@ -875,7 +875,7 @@ def test_filecache_with_checks():
875875
assert fs.cat(f1) == data * 2 # changed, since origin changed
876876

877877

878-
@pytest.mark.parametrize("impl", ["filecache", "simplecache", "blockcache"])
878+
@pytest.mark.parametrize("impl", ["filecache", "simplecache", "blockcache", "cached"])
879879
@pytest.mark.parametrize("fs", ["local", "multi"], indirect=["fs"])
880880
def test_filecache_takes_fs_instance(impl, fs):
881881
origin = tempfile.mkdtemp()
@@ -889,7 +889,7 @@ def test_filecache_takes_fs_instance(impl, fs):
889889
assert fs2.cat(f1) == data
890890

891891

892-
@pytest.mark.parametrize("impl", ["filecache", "simplecache", "blockcache"])
892+
@pytest.mark.parametrize("impl", ["filecache", "simplecache", "blockcache", "cached"])
893893
@pytest.mark.parametrize("fs", ["local", "multi"], indirect=["fs"])
894894
def test_filecache_serialization(impl, fs):
895895
fs1 = fsspec.filesystem(impl, fs=fs)
@@ -1031,7 +1031,9 @@ def test_multi_cache(protocol):
10311031
assert f.read() == b"hello"
10321032

10331033

1034-
@pytest.mark.parametrize("protocol", ["simplecache", "filecache", "blockcache"])
1034+
@pytest.mark.parametrize(
1035+
"protocol", ["simplecache", "filecache", "blockcache", "cached"]
1036+
)
10351037
def test_multi_cat(protocol, ftp_writable):
10361038
host, port, user, pw = ftp_writable
10371039
fs = FTPFileSystem(host, port, user, pw)
@@ -1064,7 +1066,9 @@ def test_multi_cache_chain(protocol):
10641066
assert files[0].read() == b"hello"
10651067

10661068

1067-
@pytest.mark.parametrize("protocol", ["blockcache", "simplecache", "filecache"])
1069+
@pytest.mark.parametrize(
1070+
"protocol", ["blockcache", "cached", "simplecache", "filecache"]
1071+
)
10681072
def test_strip(protocol):
10691073
fs = fsspec.filesystem(protocol, target_protocol="memory")
10701074
url1 = "memory://afile"
@@ -1235,9 +1239,11 @@ def test_cache_dir_auto_deleted(temp_cache, tmpdir):
12351239
assert local.exists(cache_dir)
12361240

12371241

1238-
@pytest.mark.parametrize("protocol", ["filecache", "blockcache", "simplecache"])
1242+
@pytest.mark.parametrize(
1243+
"protocol", ["filecache", "blockcache", "cached", "simplecache"]
1244+
)
12391245
def test_cache_size(tmpdir, protocol):
1240-
if win and protocol == "blockcache":
1246+
if win and protocol in {"blockcache", "cached"}:
12411247
pytest.skip("Windows file locking affects blockcache size tests")
12421248

12431249
source = os.path.join(tmpdir, "source")

0 commit comments

Comments
 (0)