Skip to content

Commit

Permalink
Pass ls kwargs through expand_path (#1242)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Martin Durant <martindurant@users.noreply.github.com>
  • Loading branch information
mariosasko and martindurant authored Apr 11, 2023
1 parent ee531c8 commit 834115f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)):
Expand Down

0 comments on commit 834115f

Please sign in to comment.