Skip to content

Commit 8db9f42

Browse files
lhoestqWauplin
authored andcommitted
[HfFileSystem] Less /paths-info calls (#2271)
* less paths-info calls * fix tests
1 parent 5737175 commit 8db9f42

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/huggingface_hub/hf_file_system.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ def info(self, path: str, refresh: bool = False, revision: Optional[str] = None,
517517
else:
518518
out = None
519519
parent_path = self._parent(path)
520+
if not expand_info and parent_path not in self.dircache:
521+
# Fill the cache with cheap call
522+
self.ls(parent_path, expand_info=False)
520523
if parent_path in self.dircache:
521524
# Check if the path is in the cache
522525
out1 = [o for o in self.dircache[parent_path] if o["name"] == path]
@@ -681,6 +684,9 @@ def __init__(self, fs: HfFileSystem, path: str, revision: Optional[str] = None,
681684
f"{e}.\nMake sure the repository and revision exist before writing data."
682685
) from e
683686
raise
687+
# avoid an unnecessary .info() call with expensive expand_info=True to instantiate .details
688+
if kwargs.get("mode", "rb") == "rb":
689+
self.details = fs.info(self.resolved_path.unresolve(), expand_info=False)
684690
super().__init__(fs, self.resolved_path.unresolve(), **kwargs)
685691
self.fs: HfFileSystem
686692

0 commit comments

Comments
 (0)