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