Skip to content

Commit d91ce4a

Browse files
committed
Mark dir fs, async wrapper as chained
1 parent 43e60fa commit d91ce4a

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

fsspec/core.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919
from fsspec.compression import compr
2020
from fsspec.config import conf
21-
from fsspec.registry import filesystem, get_filesystem_class
21+
from fsspec.registry import available_protocols, filesystem, get_filesystem_class
2222
from fsspec.utils import (
2323
_unstrip_protocol,
2424
build_name_function,
@@ -334,34 +334,47 @@ def _un_chain(path, kwargs):
334334

335335
if "::" in path:
336336
x = re.compile(".*[^a-z]+.*") # test for non protocol-like single word
337+
known_protocols = set(available_protocols())
337338
bits = []
339+
340+
# split on '::', then ensure each bit has a protocol
338341
for p in path.split("::"):
339-
if "://" in p or x.match(p):
342+
if p in known_protocols:
343+
bits.append(p + "://")
344+
elif "://" in p or x.match(p):
340345
bits.append(p)
341346
else:
342347
bits.append(p + "://")
343348
else:
344349
bits = [path]
350+
345351
# [[url, protocol, kwargs], ...]
346352
out = []
347353
previous_bit = None
348354
kwargs = kwargs.copy()
355+
349356
for bit in reversed(bits):
350357
protocol = kwargs.pop("protocol", None) or split_protocol(bit)[0] or "file"
351358
cls = get_filesystem_class(protocol)
352359
extra_kwargs = cls._get_kwargs_from_urls(bit)
353360
kws = kwargs.pop(protocol, {})
361+
354362
if bit is bits[0]:
355363
kws.update(kwargs)
364+
356365
kw = dict(
357366
**{k: v for k, v in extra_kwargs.items() if k not in kws or v != kws[k]},
358367
**kws,
359368
)
360369
bit = cls._strip_protocol(bit)
361-
if "target_protocol" not in kw and issubclass(cls, ChainedFileSystem):
370+
371+
if "target_protocol" not in kw and issubclass(cls, ChainedFileSystem) and not bit:
372+
# replace bit if we are chaining and no path given
362373
bit = previous_bit
374+
363375
out.append((bit, protocol, kw))
364376
previous_bit = bit
377+
365378
out.reverse()
366379
return out
367380

fsspec/implementations/asyn_wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import fsspec
66
from fsspec.asyn import AsyncFileSystem, running_async
7+
from .chained import ChainedFileSystem
78

89

910
def async_wrapper(func, obj=None, semaphore=None):
@@ -35,7 +36,7 @@ async def wrapper(*args, **kwargs):
3536
return wrapper
3637

3738

38-
class AsyncFileSystemWrapper(AsyncFileSystem):
39+
class AsyncFileSystemWrapper(AsyncFileSystem, ChainedFileSystem):
3940
"""
4041
A wrapper class to convert a synchronous filesystem into an asynchronous one.
4142

fsspec/implementations/dirfs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from .. import filesystem
22
from ..asyn import AsyncFileSystem
3+
from .chained import ChainedFileSystem
34

45

5-
class DirFileSystem(AsyncFileSystem):
6+
class DirFileSystem(AsyncFileSystem, ChainedFileSystem):
67
"""Directory prefix filesystem
78
89
The DirFileSystem is a filesystem-wrapper. It assumes every path it is dealing with

fsspec/registry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def register_implementation(name, cls, clobber=False, errtxt=None):
7272
"class": "fsspec.implementations.arrow.HadoopFileSystem",
7373
"err": "pyarrow and local java libraries required for HDFS",
7474
},
75+
"async_wrapper": {
76+
"class": "fsspec.implementations.asyn_wrapper.AsyncFileSystemWrapper",
77+
},
7578
"asynclocal": {
7679
"class": "morefs.asyn_local.AsyncLocalFileSystem",
7780
"err": "Install 'morefs[asynclocalfs]' to use AsyncLocalFileSystem",

0 commit comments

Comments
 (0)