[exportdb] Fix generating docs (#107838)
Previously I accidentally replaced all `=` with `-`, resulting in clowny code rendering like:

The purpose of replacing the `=` with `-` is to change the RST heading size of modules. So now, I replace strings with more than 3 `=`'s with `-`. This should avoid incorrectly replacing code where we set variables with `=` and do equality checks with `==`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/107838
Approved by: https://github.com/gmagogsfm
diff --git a/docs/source/scripts/exportdb/generate_example_rst.py b/docs/source/scripts/exportdb/generate_example_rst.py
index 88697f6..7aedcb1 100644
--- a/docs/source/scripts/exportdb/generate_example_rst.py
+++ b/docs/source/scripts/exportdb/generate_example_rst.py
@@ -145,7 +145,11 @@
for tag, modules_rst in tag_to_modules.items():
doc_contents = f"{tag}\n{'=' * (len(tag) + 4)}\n"
- doc_contents += "\n\n".join(modules_rst).replace("=", "-")
+ full_modules_rst = "\n\n".join(modules_rst)
+ full_modules_rst = re.sub(
+ r"={3,}", lambda match: "-" * len(match.group()), full_modules_rst
+ )
+ doc_contents += full_modules_rst
with open(os.path.join(EXPORTDB_SOURCE, f"{tag}.rst"), "w") as f:
f.write(doc_contents)