From 834115f2b91f61d09004beb1bfd46d705a201c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20=C5=A0a=C5=A1ko?= Date: Tue, 11 Apr 2023 20:15:51 +0200 Subject: [PATCH] Pass `ls` kwargs through `expand_path` (#1242) --------- Co-authored-by: Martin Durant --- fsspec/spec.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fsspec/spec.py b/fsspec/spec.py index bc89c3a02..7bbf09099 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -995,9 +995,12 @@ def copy(self, path1, path2, recursive=False, on_error=None, **kwargs): if on_error == "raise": raise - def expand_path(self, path, recursive=False, maxdepth=None): + def expand_path(self, path, recursive=False, maxdepth=None, **kwargs): """Turn one or more globs or directories into a list of all matching paths - to files or directories.""" + to files or directories. + + kwargs are passed to ``glob`` or ``find``, which may in turn call ``ls`` + """ if maxdepth is not None and maxdepth < 1: raise ValueError("maxdepth must be at least 1") @@ -1008,18 +1011,23 @@ def expand_path(self, path, recursive=False, maxdepth=None): path = [self._strip_protocol(p) for p in path] for p in path: if has_magic(p): - bit = set(self.glob(p)) + bit = set(self.glob(p, **kwargs)) out |= bit if recursive: out |= set( self.expand_path( - list(bit), recursive=recursive, maxdepth=maxdepth + list(bit), + recursive=recursive, + maxdepth=maxdepth, + **kwargs, ) ) continue elif recursive: rec = set( - self.find(p, maxdepth=maxdepth, withdirs=True, detail=False) + self.find( + p, maxdepth=maxdepth, withdirs=True, detail=False, **kwargs + ) ) out |= rec if p not in out and (recursive is False or self.exists(p)):