MCPcopy
hub / github.com/pandas-dev/pandas / find_titles

Function find_titles

scripts/validate_rst_title_capitalization.py:215–248  ·  view source on GitHub ↗

Algorithm to identify particular text that should be considered headings in an RST file. See <https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html> for details on what constitutes a string as a heading in RST. Parameters ---------- rst_file : str RST

(rst_file: str)

Source from the content-addressed store, hash-verified

213
214
215def find_titles(rst_file: str) -> Iterable[tuple[str, int]]:
216 """
217 Algorithm to identify particular text that should be considered headings in an
218 RST file.
219
220 See <https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html> for details
221 on what constitutes a string as a heading in RST.
222
223 Parameters
224 ----------
225 rst_file : str
226 RST file to scan through for headings.
227
228 Yields
229 -------
230 title : str
231 A heading found in the rst file.
232
233 line_number : int
234 The corresponding line number of the heading.
235 """
236
237 with open(rst_file, encoding="utf-8") as fd:
238 previous_line = ""
239 for i, line in enumerate(fd):
240 line_no_last_elem = line[:-1]
241 line_chars = set(line_no_last_elem)
242 if (
243 len(line_chars) == 1
244 and line_chars.pop() in symbols
245 and len(line_no_last_elem) == len(previous_line)
246 ):
247 yield re.sub(r"[`\*_]", "", previous_line), i
248 previous_line = line_no_last_elem
249
250
251def main(source_paths: list[str]) -> int:

Callers 1

mainFunction · 0.85

Calls 2

popMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected