Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin fsspec to use default expand_path #1681

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading