From 0071252c2c5363f3599dd76db42468eb0ee6d791 Mon Sep 17 00:00:00 2001 From: Elliana May Date: Mon, 10 Jul 2023 21:20:08 +0800 Subject: [PATCH] fix(dirfs): allow protocol prefixed paths (#1307) * fix(dirfs): allow protocol prefixed paths * lint --------- Co-authored-by: Martin Durant --- fsspec/implementations/dirfs.py | 4 +++- fsspec/implementations/tests/test_dirfs.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fsspec/implementations/dirfs.py b/fsspec/implementations/dirfs.py index 3e6def1f5..bafd48457 100644 --- a/fsspec/implementations/dirfs.py +++ b/fsspec/implementations/dirfs.py @@ -10,6 +10,8 @@ class DirFileSystem(AsyncFileSystem): delegates everything to the wrapped filesystem. """ + protocol = "dirfs" + def __init__( self, path=None, @@ -53,7 +55,7 @@ def _join(self, path): return path if not path: return self.path - return self.fs.sep.join((self.path, path)) + return self.fs.sep.join((self.path, self._strip_protocol(path))) return [self._join(_path) for _path in path] def _relpath(self, path): diff --git a/fsspec/implementations/tests/test_dirfs.py b/fsspec/implementations/tests/test_dirfs.py index 402f8f67d..9cf97c969 100644 --- a/fsspec/implementations/tests/test_dirfs.py +++ b/fsspec/implementations/tests/test_dirfs.py @@ -372,6 +372,12 @@ def test_glob(dirfs): dirfs.fs.glob.assert_called_once_with(f"{PATH}/*", **KWARGS) +def test_glob_with_protocol(dirfs): + dirfs.fs.glob.return_value = [f"{PATH}/one", f"{PATH}/two"] + assert dirfs.glob("dirfs://*", **KWARGS) == ["one", "two"] + dirfs.fs.glob.assert_called_once_with(f"{PATH}/*", **KWARGS) + + @pytest.mark.asyncio async def test_async_glob_detail(adirfs): adirfs.fs._glob.return_value = {