CoolFace
Apppublic

declare-lab/tango2

sourceHugging Faceupdated 2y agoView on Hugging Face
92likes
doc_utils.py39 linesDownload Raw Back to utils
1# Copyright 2023 The HuggingFace Team. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""15Doc utilities: Utilities related to documentation16"""17import re18 19 20def replace_example_docstring(example_docstring):21    def docstring_decorator(fn):22        func_doc = fn.__doc__23        lines = func_doc.split("\n")24        i = 025        while i < len(lines) and re.search(r"^\s*Examples?:\s*$", lines[i]) is None:26            i += 127        if i < len(lines):28            lines[i] = example_docstring29            func_doc = "\n".join(lines)30        else:31            raise ValueError(32                f"The function {fn} should have an empty 'Examples:' in its docstring as placeholder, "33                f"current docstring is:\n{func_doc}"34            )35        fn.__doc__ = func_doc36        return fn37 38    return docstring_decorator39