in python/scripts/generate_type_stubs_and_docs.py [0:0]
def postprocess_sphinx_output(directory: str, renames: Dict[str, str]):
"""
I've spent 7 hours of my time this weekend fighting with Sphinx.
Rather than find the "correct" way to fix this, I'm just going to
overwrite the HTML output with good old find-and-replace.
"""
for html_path in pathlib.Path(directory).rglob("*.html"):
html_contents = html_path.read_text()
for find, replace in renames.items():
results = re.findall(find, html_contents)
if results:
html_contents = re.sub(find, replace, html_contents)
with open(html_path, "w") as f:
f.write(html_contents)