| 1 |
""" |
| 2 |
This tool is used during CI testing to make sure sphinx raise no error. |
| 3 |
|
| 4 |
During development, we like to have whatsnew/pr/*.rst documents to track |
| 5 |
individual new features. Unfortunately they other either: |
| 6 |
- have no title (sphinx complains) |
| 7 |
- are not included in any toctree (sphinx complain) |
| 8 |
|
| 9 |
This fix-them up by "inventing" a title, before building the docs. At release |
| 10 |
time, these title and files will anyway be rewritten into the actual release |
| 11 |
notes. |
| 12 |
""" |
| 13 |
|
| 14 |
from pathlib import Path |
| 15 |
|
| 16 |
|
| 17 |
def main(): |
| 18 |
folder = Path("docs/source/whatsnew/pr/") |
| 19 |
files = list(folder.glob("*.rst")) |
| 20 |
print(files) |
| 21 |
|
| 22 |
for filepath in files: |
| 23 |
print("Adding pseudo-title to:", filepath.name) |
| 24 |
title = filepath.name[:-4].split("/")[-1].replace("-", " ").capitalize() |
| 25 |
|
| 26 |
data = filepath.read_text(encoding="utf-8") |
| 27 |
try: |
| 28 |
if data and data.splitlines()[1].startswith("="): |
| 29 |
continue |
| 30 |
except IndexError: |
| 31 |
pass |
| 32 |
|
| 33 |
with filepath.open("w", encoding="utf-8") as f: |
| 34 |
f.write(title + "\n") |
| 35 |
f.write("=" * len(title) + "\n\n") |
| 36 |
f.write(data) |
| 37 |
|
| 38 |
|
| 39 |
if __name__ == "__main__": |
| 40 |
main() |