From a980d8f3df939946fc089fa0e43093b3d045e8ab Mon Sep 17 00:00:00 2001 From: Michael Scheiwiller Date: Fri, 5 Jul 2024 17:23:52 +0200 Subject: [PATCH 1/4] feat: add fsspec docstrings to HfFileSystem in docs --- .../source/en/package_reference/hf_file_system.md | 5 ++--- src/huggingface_hub/hf_file_system.py | 15 +++++++++++++++ 2 files changed, 17 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..cc97eb3f74 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,17 @@ 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: + 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__ + ) From 1ecc7101bdfc9c9b7011a2eeec49c90fc2c576de Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 9 Jul 2024 09:08:13 +0200 Subject: [PATCH 2/4] fix --- src/huggingface_hub/hf_file_system.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index cc97eb3f74..18e155ed4a 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -896,11 +896,13 @@ def reopen(fs: HfFileSystem, path: str, mode: str, block_size: int, cache_type: 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.replace("-" * 10, "\n").replace("-" * 7, "\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__ + + parent_doc ) From 7831047eb926a4aaff697b1480830b2cc157a170 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 9 Jul 2024 09:09:31 +0200 Subject: [PATCH 3/4] add . --- src/huggingface_hub/hf_file_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index 18e155ed4a..49e838fdd5 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -901,7 +901,7 @@ def reopen(fs: HfFileSystem, path: str, mode: str, block_size: int, cache_type: function.__doc__ = ( ( "\n_Docstring taken from " - f"[fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.{name})_" + f"[fsspec documentation](https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem.{name})._" ) + "\n\n" + parent_doc From 02d4455d0897d90b818a61b0cbc79397236492a8 Mon Sep 17 00:00:00 2001 From: Lucain Pouget Date: Tue, 9 Jul 2024 09:15:48 +0200 Subject: [PATCH 4/4] format --- src/huggingface_hub/hf_file_system.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index 49e838fdd5..660f51225f 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -897,7 +897,8 @@ def reopen(fs: HfFileSystem, path: str, mode: str, block_size: int, cache_type: parent = getattr(fsspec.AbstractFileSystem, name, None) if parent is not None and parent.__doc__ is not None: parent_doc = parent.__doc__ - parent_doc.replace("-" * 10, "\n").replace("-" * 7, "\n") + 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 "