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

Function keep_doc_examples_only

utils/tests_fetcher.py:138–162  ·  view source on GitHub ↗

Remove everything from the code content except the doc examples (used to determined if a diff should trigger doc tests or not). Args: content (`str`): The code to clean Returns: `str`: The cleaned code.

(content: str)

Source from the content-addressed store, hash-verified

136
137
138def keep_doc_examples_only(content: str) -> str:
139 """
140 Remove everything from the code content except the doc examples (used to determined if a diff should trigger doc
141 tests or not).
142
143 Args:
144 content (`str`): The code to clean
145
146 Returns:
147 `str`: The cleaned code.
148 """
149 # Keep doc examples only by splitting on triple "`"
150 splits = content.split("```")
151 # Add leading and trailing "```" so the navigation is easier when compared to the original input `content`
152 content = "```" + "```".join(splits[1::2]) + "```"
153
154 # Remove empty lines and comments
155 lines_to_keep = []
156 for line in content.split("\n"):
157 # remove anything that is after a # sign.
158 line = re.sub("#.*$", "", line)
159 # remove white lines
160 if len(line) != 0 and not line.isspace():
161 lines_to_keep.append(line)
162 return "\n".join(lines_to_keep)
163
164
165def get_all_tests() -> List[str]:

Callers 1

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…