File: fixup_whats_new_pr.py

package info (click to toggle)
ipython 8.35.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,636 kB
  • sloc: python: 42,461; sh: 376; makefile: 243
file content (39 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
This tool is used during CI testing to make sure sphinx raise no error.

During development, we like to have whatsnew/pr/*.rst documents to track
individual new features. Unfortunately they other either:
  - have no title (sphinx complains)
  - are not included in any toctree (sphinx complain)

This fix-them up by "inventing" a title, before building the docs. At release
time, these title and files will anyway be rewritten into the actual release
notes.
"""

from pathlib import Path

def main():
    folder = Path("docs/source/whatsnew/pr/")
    files = list(folder.glob("*.rst"))
    print(files)

    for filepath in files:
        print("Adding pseudo-title to:", filepath.name)
        title = filepath.name[:-4].split("/")[-1].replace("-", " ").capitalize()

        data = filepath.read_text(encoding="utf-8")
        try:
            if data and data.splitlines()[1].startswith('='):
                continue
        except IndexError:
            pass

        with filepath.open("w", encoding="utf-8") as f:
            f.write(title + "\n")
            f.write("=" * len(title) + "\n\n")
            f.write(data)

if __name__ == '__main__':
    main()