Skip to content

Commit 04eb6ed

Browse files
lhoestqhanouticelina
authored andcommitted
[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 05f6cab commit 04eb6ed

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
@@ -160,13 +167,15 @@ def __init__(
160167
endpoint: Optional[str] = None,
161168
token: Union[bool, str, None] = None,
162169
block_size: Optional[int] = None,
170+
expand_info: Optional[bool] = None,
163171
**storage_options,
164172
):
165173
super().__init__(*args, **storage_options)
166174
self.endpoint = endpoint or constants.ENDPOINT
167175
self.token = token
168176
self._api = HfApi(endpoint=endpoint, token=token)
169177
self.block_size = block_size
178+
self.expand_info = expand_info
170179
# Maps (repo_type, repo_id, revision) to a 2-tuple with:
171180
# * the 1st element indicating whether the repositoy and the revision exist
172181
# * the 2nd element being the exception raised if the repository or revision doesn't exist
@@ -453,9 +462,12 @@ def _ls_tree(
453462
recursive: bool = False,
454463
refresh: bool = False,
455464
revision: Optional[str] = None,
456-
expand_info: bool = False,
465+
expand_info: Optional[bool] = None,
457466
maxdepth: Optional[int] = None,
458467
):
468+
expand_info = (
469+
expand_info if expand_info is not None else (self.expand_info if self.expand_info is not None else False)
470+
)
459471
resolved_path = self.resolve_path(path, revision=revision)
460472
path = resolved_path.unresolve()
461473
root_path = HfFileSystemResolvedPath(
@@ -756,7 +768,7 @@ def info(self, path: str, refresh: bool = False, revision: Optional[str] = None,
756768
resolved_path = self.resolve_path(path, revision=revision)
757769
path = resolved_path.unresolve()
758770
expand_info = kwargs.get(
759-
"expand_info", False
771+
"expand_info", self.expand_info if self.expand_info is not None else False
760772
) # don't expose it as a parameter in the public API to follow the spec
761773
if not resolved_path.path_in_repo:
762774
# Path is the root directory

0 commit comments

Comments
 (0)