Skip to content

Commit

Permalink
Pin fsspec to use default expand_path (#1681)
Browse files Browse the repository at this point in the history
* Use default `expand_path` in newer fsspec versions

* Nit

* Bump fsspec
  • Loading branch information
mariosasko authored Sep 21, 2023
1 parent e3061b4 commit 6c2ebcc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_version() -> str:

install_requires = [
"filelock",
"fsspec",
"fsspec>=2023.5.0",
"requests",
"tqdm>=4.42.1",
"pyyaml>=5.1",
Expand Down
30 changes: 0 additions & 30 deletions src/huggingface_hub/hf_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tempfile
from dataclasses import dataclass
from datetime import datetime
from glob import has_magic
from typing import Any, Dict, List, Optional, Tuple, Union
from urllib.parse import quote, unquote

Expand Down Expand Up @@ -375,35 +374,6 @@ def info(self, path: str, **kwargs) -> Dict[str, Any]:
return {"name": name, "size": 0, "type": "directory"}
return super().info(path, **kwargs)

def expand_path(
self, path: Union[str, List[str]], recursive: bool = False, maxdepth: Optional[int] = None, **kwargs
) -> List[str]:
# The default implementation does not allow passing custom kwargs (e.g., we use these kwargs to propagate the `revision`)
if maxdepth is not None and maxdepth < 1:
raise ValueError("maxdepth must be at least 1")

if isinstance(path, str):
return self.expand_path([path], recursive, maxdepth)

out = set()
path = [self._strip_protocol(p) for p in path]
for p in path:
if has_magic(p):
bit = set(self.glob(p, **kwargs))
out |= bit
if recursive:
out |= set(self.expand_path(list(bit), recursive=recursive, maxdepth=maxdepth, **kwargs))
continue
elif recursive:
rec = set(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)):
# should only check once, for the root
out.add(p)
if not out:
raise FileNotFoundError(path)
return list(sorted(out))


class HfFileSystemFile(fsspec.spec.AbstractBufferedFile):
def __init__(self, fs: HfFileSystem, path: str, revision: Optional[str] = None, **kwargs):
Expand Down

0 comments on commit 6c2ebcc

Please sign in to comment.