Skip to content

Commit

Permalink
Document more HfFilesyStem Methods (#2380)
Browse files Browse the repository at this point in the history
* feat: add fsspec docstrings to HfFileSystem in docs

* fix

* add .

* format

---------

Co-authored-by: Lucain Pouget <lucainp@gmail.com>
  • Loading branch information
lappemic and Wauplin authored Jul 9, 2024
1 parent ca111fb commit 33b02b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions docs/source/en/package_reference/hf_file_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ The `HfFileSystem` class provides a pythonic file interface to the Hugging Face

`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).

[[autodoc]] HfFileSystem
[[autodoc]] HfFileSystem
- __init__
- resolve_path
- ls
- all
18 changes: 18 additions & 0 deletions src/huggingface_hub/hf_file_system.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import os
import re
import tempfile
Expand Down Expand Up @@ -889,3 +890,20 @@ def _raise_file_not_found(path: str, err: Optional[Exception]) -> NoReturn:

def reopen(fs: HfFileSystem, path: str, mode: str, block_size: int, cache_type: str):
return fs.open(path, mode=mode, block_size=block_size, cache_type=cache_type)


# Add docstrings to the methods of HfFileSystem from fsspec.AbstractFileSystem
for name, function in inspect.getmembers(HfFileSystem, predicate=inspect.isfunction):
parent = getattr(fsspec.AbstractFileSystem, name, None)
if parent is not None and parent.__doc__ is not None:
parent_doc = parent.__doc__
parent_doc = parent_doc.replace("Parameters\n ----------\n", "Args:\n")
parent_doc = parent_doc.replace("Returns\n -------\n", "Return:\n")
function.__doc__ = (
(
"\n_Docstring taken from "
f"[fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.{name})._"
)
+ "\n\n"
+ parent_doc
)

0 comments on commit 33b02b5

Please sign in to comment.