MCPcopy Index your code
hub / github.com/huggingface/diffusers / clean_code

Function clean_code

utils/tests_fetcher.py:106–135  ·  view source on GitHub ↗

Remove docstrings, empty line or comments from some code (used to detect if a diff is real or only concern comments or docstrings). Args: content (`str`): The code to clean Returns: `str`: The cleaned code.

(content: str)

Source from the content-addressed store, hash-verified

104
105
106def clean_code(content: str) -> str:
107 """
108 Remove docstrings, empty line or comments from some code (used to detect if a diff is real or only concern
109 comments or docstrings).
110
111 Args:
112 content (`str`): The code to clean
113
114 Returns:
115 `str`: The cleaned code.
116 """
117 # We need to deactivate autoformatting here to write escaped triple quotes (we cannot use real triple quotes or
118 # this would mess up the result if this function applied to this particular file).
119 # fmt: off
120 # Remove docstrings by splitting on triple " then triple ':
121 splits = content.split('\"\"\"')
122 content = "".join(splits[::2])
123 splits = content.split("\'\'\'")
124 # fmt: on
125 content = "".join(splits[::2])
126
127 # Remove empty lines and comments
128 lines_to_keep = []
129 for line in content.split("\n"):
130 # remove anything that is after a # sign.
131 line = re.sub("#.*$", "", line)
132 # remove white lines
133 if len(line) != 0 and not line.isspace():
134 lines_to_keep.append(line)
135 return "\n".join(lines_to_keep)
136
137
138def keep_doc_examples_only(content: str) -> str:

Callers 1

diff_is_docstring_onlyFunction · 0.85

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…