Skip to content

Commit 7aa982a

Browse files
fix: Ensure kwargs passed via expand_path (#1911)
--------- Co-authored-by: Martin Durant <[email protected]>
1 parent 01f2fd4 commit 7aa982a

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

fsspec/spec.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs):
892892
dict of {path: contents} if there are multiple paths
893893
or the path has been otherwise expanded
894894
"""
895-
paths = self.expand_path(path, recursive=recursive)
895+
paths = self.expand_path(path, recursive=recursive, **kwargs)
896896
if (
897897
len(paths) > 1
898898
or isinstance(path, list)
@@ -972,7 +972,9 @@ def get(
972972
)
973973

974974
source_is_str = isinstance(rpath, str)
975-
rpaths = self.expand_path(rpath, recursive=recursive, maxdepth=maxdepth)
975+
rpaths = self.expand_path(
976+
rpath, recursive=recursive, maxdepth=maxdepth, **kwargs
977+
)
976978
if source_is_str and (not recursive or maxdepth is not None):
977979
# Non-recursive glob does not copy directories
978980
rpaths = [p for p in rpaths if not (trailing_sep(p) or self.isdir(p))]
@@ -1060,7 +1062,9 @@ def put(
10601062
if source_is_str:
10611063
lpath = make_path_posix(lpath)
10621064
fs = LocalFileSystem()
1063-
lpaths = fs.expand_path(lpath, recursive=recursive, maxdepth=maxdepth)
1065+
lpaths = fs.expand_path(
1066+
lpath, recursive=recursive, maxdepth=maxdepth, **kwargs
1067+
)
10641068
if source_is_str and (not recursive or maxdepth is not None):
10651069
# Non-recursive glob does not copy directories
10661070
lpaths = [p for p in lpaths if not (trailing_sep(p) or fs.isdir(p))]
@@ -1131,7 +1135,9 @@ def copy(
11311135
from .implementations.local import trailing_sep
11321136

11331137
source_is_str = isinstance(path1, str)
1134-
paths1 = self.expand_path(path1, recursive=recursive, maxdepth=maxdepth)
1138+
paths1 = self.expand_path(
1139+
path1, recursive=recursive, maxdepth=maxdepth, **kwargs
1140+
)
11351141
if source_is_str and (not recursive or maxdepth is not None):
11361142
# Non-recursive glob does not copy directories
11371143
paths1 = [p for p in paths1 if not (trailing_sep(p) or self.isdir(p))]
@@ -1172,7 +1178,7 @@ def expand_path(self, path, recursive=False, maxdepth=None, **kwargs):
11721178
raise ValueError("maxdepth must be at least 1")
11731179

11741180
if isinstance(path, (str, os.PathLike)):
1175-
out = self.expand_path([path], recursive, maxdepth)
1181+
out = self.expand_path([path], recursive, maxdepth, **kwargs)
11761182
else:
11771183
out = set()
11781184
path = [self._strip_protocol(p) for p in path]

fsspec/tests/test_spec.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,3 +1375,41 @@ def test_glob_posix_rules(path, expected, glob_fs):
13751375
detailed_output = glob_fs.glob(path=f"mock://{path}", detail=True)
13761376
for name, info in _clean_paths(detailed_output).items():
13771377
assert info == glob_fs[name]
1378+
1379+
1380+
@pytest.fixture(scope="function")
1381+
def tmpfs(tmpdir):
1382+
get_files(tmpdir)
1383+
1384+
class CustomLocalFS(LocalFileSystem):
1385+
def ls(self, *args, **kwargs):
1386+
files = super().ls(*args, **kwargs)
1387+
limit = kwargs.pop("limit", None)
1388+
1389+
return files[:limit] if limit else files
1390+
1391+
return CustomLocalFS(auto_mkdir=True)
1392+
1393+
1394+
def test_cat_wildcard_path_passthrough_kwargs_to_ls(tmpfs, tmpdir):
1395+
file_contents = tmpfs.cat(tmpdir / "*", limit=2)
1396+
assert len(file_contents) == 2
1397+
1398+
1399+
def test_get_wildcard_path_passthrough_kwargs_to_ls(tmpfs, tmpdir):
1400+
dest = tmpdir / "dest"
1401+
tmpfs.get(tmpdir / "*", str(dest), limit=2)
1402+
1403+
assert len(dest.listdir()) == 2
1404+
1405+
1406+
def test_copy_wildcard_path_passthrough_kwargs_to_ls(tmpfs, tmpdir):
1407+
dest = tmpdir / "dest"
1408+
tmpfs.copy(tmpdir / "*", str(dest), limit=2)
1409+
1410+
assert len(dest.listdir()) == 2
1411+
1412+
1413+
def test_expand_path_wildcard_path_passthrough_kwargs_to_ls(tmpfs, tmpdir):
1414+
expanded_paths = tmpfs.expand_path(tmpdir / "*", limit=2)
1415+
assert len(expanded_paths) == 2

0 commit comments

Comments
 (0)