Skip to content

Commit

Permalink
[HfFileSystem] Less /paths-info calls (#2271)
Browse files Browse the repository at this point in the history
* less paths-info calls

* fix tests
  • Loading branch information
lhoestq authored and Wauplin committed May 21, 2024
1 parent 5737175 commit 8db9f42
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/huggingface_hub/hf_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ def info(self, path: str, refresh: bool = False, revision: Optional[str] = None,
else:
out = None
parent_path = self._parent(path)
if not expand_info and parent_path not in self.dircache:
# Fill the cache with cheap call
self.ls(parent_path, expand_info=False)
if parent_path in self.dircache:
# Check if the path is in the cache
out1 = [o for o in self.dircache[parent_path] if o["name"] == path]
Expand Down Expand Up @@ -681,6 +684,9 @@ def __init__(self, fs: HfFileSystem, path: str, revision: Optional[str] = None,
f"{e}.\nMake sure the repository and revision exist before writing data."
) from e
raise
# avoid an unnecessary .info() call with expensive expand_info=True to instantiate .details
if kwargs.get("mode", "rb") == "rb":
self.details = fs.info(self.resolved_path.unresolve(), expand_info=False)
super().__init__(fs, self.resolved_path.unresolve(), **kwargs)
self.fs: HfFileSystem

Expand Down

0 comments on commit 8db9f42

Please sign in to comment.