Skip to content

Commit 1fcdfd8

Browse files
[HfFileSystem] add expand_info arg (#3575)
* hffs: expand_info arg * style * Update src/huggingface_hub/hf_file_system.py Co-authored-by: célina <[email protected]> * up-to-date HfFileSystem docstring --------- Co-authored-by: célina <[email protected]>
1 parent 6a66890 commit 1fcdfd8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

docs/source/en/package_reference/hf_file_system.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ The `HfFileSystem` class provides a pythonic file interface to the Hugging Face
1010

1111
`HfFileSystem` is based on [fsspec](https://filesystem-spec.readthedocs.io/en/latest/), so it is compatible with most of the APIs that it offers. For more details, check out [our guide](../guides/hf_file_system) and fsspec's [API Reference](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem).
1212

13-
[[autodoc]] HfFileSystem
14-
- __init__
15-
- all
13+
[[autodoc]] HfFileSystem

src/huggingface_hub/hf_file_system.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,20 @@ class HfFileSystem(fsspec.AbstractFileSystem, metaclass=_Cached):
123123
> layer. For better performance and reliability, it's recommended to use `HfApi` methods when possible.
124124
125125
Args:
126-
token (`str` or `bool`, *optional*):
126+
endpoint (`str`, *optional*):
127+
Endpoint of the Hub. Defaults to <https://huggingface.co>.
128+
token (`bool` or `str`, *optional*):
127129
A valid user access token (string). Defaults to the locally saved
128130
token, which is the recommended method for authentication (see
129131
https://huggingface.co/docs/huggingface_hub/quick-start#authentication).
130132
To disable authentication, pass `False`.
131-
endpoint (`str`, *optional*):
132-
Endpoint of the Hub. Defaults to <https://huggingface.co>.
133+
block_size (`int`, *optional*):
134+
Block size for reading and writing files.
135+
expand_info (`bool`, *optional*):
136+
Whether to expand the information of the files.
137+
**storage_options (`dict`, *optional*):
138+
Additional options for the filesystem. See [fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.__init__).
139+
133140
Usage:
134141
135142
```python
@@ -164,13 +171,15 @@ def __init__(
164171
endpoint: Optional[str] = None,
165172
token: Union[bool, str, None] = None,
166173
block_size: Optional[int] = None,
174+
expand_info: Optional[bool] = None,
167175
**storage_options,
168176
):
169177
super().__init__(*args, **storage_options)
170178
self.endpoint = endpoint or constants.ENDPOINT
171179
self.token = token
172180
self._api = HfApi(endpoint=endpoint, token=token)
173181
self.block_size = block_size
182+
self.expand_info = expand_info
174183
# Maps (repo_type, repo_id, revision) to a 2-tuple with:
175184
# * the 1st element indicating whether the repositoy and the revision exist
176185
# * the 2nd element being the exception raised if the repository or revision doesn't exist
@@ -457,9 +466,12 @@ def _ls_tree(
457466
recursive: bool = False,
458467
refresh: bool = False,
459468
revision: Optional[str] = None,
460-
expand_info: bool = False,
469+
expand_info: Optional[bool] = None,
461470
maxdepth: Optional[int] = None,
462471
):
472+
expand_info = (
473+
expand_info if expand_info is not None else (self.expand_info if self.expand_info is not None else False)
474+
)
463475
resolved_path = self.resolve_path(path, revision=revision)
464476
path = resolved_path.unresolve()
465477
root_path = HfFileSystemResolvedPath(
@@ -760,7 +772,7 @@ def info(self, path: str, refresh: bool = False, revision: Optional[str] = None,
760772
resolved_path = self.resolve_path(path, revision=revision)
761773
path = resolved_path.unresolve()
762774
expand_info = kwargs.get(
763-
"expand_info", False
775+
"expand_info", self.expand_info if self.expand_info is not None else False
764776
) # don't expose it as a parameter in the public API to follow the spec
765777
if not resolved_path.path_in_repo:
766778
# Path is the root directory

0 commit comments

Comments
 (0)