From 33b02b5e0336a229a8d5874fdf866c33c1c6bfe9 Mon Sep 17 00:00:00 2001 From: Michael <61876623+lappemic@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:21:44 +0200 Subject: [PATCH] Document more `HfFilesyStem` Methods (#2380) * feat: add fsspec docstrings to HfFileSystem in docs * fix * add . * format --------- Co-authored-by: Lucain Pouget --- .../en/package_reference/hf_file_system.md | 5 ++--- src/huggingface_hub/hf_file_system.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/source/en/package_reference/hf_file_system.md b/docs/source/en/package_reference/hf_file_system.md index f203ebd070..097c798fa7 100644 --- a/docs/source/en/package_reference/hf_file_system.md +++ b/docs/source/en/package_reference/hf_file_system.md @@ -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 diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index 44c5aba17d..660f51225f 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -1,3 +1,4 @@ +import inspect import os import re import tempfile @@ -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 + )