##// END OF EJS Templates
Add script to update whatsnew file from PR snippets
Thomas Kluyver -
Show More
@@ -0,0 +1,74 b''
1 """Update the What's New doc (development version)
2
3 This collects the snippets from whatsnew/pr/, moves their content into
4 whatsnew/development.rst (chronologically ordered), and deletes the snippets.
5 """
6
7 import io
8 import os
9 from os.path import dirname, basename, abspath, join as pjoin
10 from subprocess import check_call, check_output
11
12 repo_root = dirname(dirname(abspath(__file__)))
13 whatsnew_dir = pjoin(repo_root, 'docs', 'source', 'whatsnew')
14 pr_dir = pjoin(whatsnew_dir, 'pr')
15 target = pjoin(whatsnew_dir, 'development.rst')
16
17 FEATURE_MARK = ".. DO NOT EDIT THIS LINE BEFORE RELEASE. FEATURE INSERTION POINT."
18 INCOMPAT_MARK = ".. DO NOT EDIT THIS LINE BEFORE RELEASE. INCOMPAT INSERTION POINT."
19
20 # 1. Collect the whatsnew snippet files ---------------------------------------
21
22 files = set(os.listdir(pr_dir))
23 # Ignore explanatory and example files
24 files.difference_update({'README.md',
25 'incompat-switching-to-perl.rst',
26 'antigravity-feature.rst'}
27 )
28
29 # Absolute paths
30 files = {pjoin(pr_dir, f) for f in files}
31
32 def getmtime(f):
33 return check_output(['git', 'log', '-1', '--format="%ai"', '--', f])
34
35 files = sorted(files, key=getmtime)
36
37 features, incompats = [], []
38 for path in files:
39 with io.open(path, encoding='utf-8') as f:
40 content = f.read().rstrip()
41 if basename(path).startswith('incompat-'):
42 incompats.append(content)
43 else:
44 features.append(content)
45
46 # Put the insertion markers back on the end, so they're ready for next time.
47 feature_block = '\n\n'.join(features + [FEATURE_MARK])
48 incompat_block = '\n\n'.join(incompats + [INCOMPAT_MARK])
49
50 # 2. Update the target file ---------------------------------------------------
51
52 with io.open(target, encoding='utf-8') as f:
53 content = f.read()
54
55 assert content.count(FEATURE_MARK) == 1
56 assert content.count(INCOMPAT_MARK) == 1
57
58 content = content.replace(FEATURE_MARK, feature_block)
59 content = content.replace(INCOMPAT_MARK, incompat_block)
60
61 # Clean trailing whitespace
62 content = '\n'.join(l.rstrip() for l in content.splitlines())
63
64 with io.open(target, 'w', encoding='utf-8') as f:
65 f.write(content)
66
67 # 3. Stage the changes in git -------------------------------------------------
68
69 for file in files:
70 check_call(['git', 'rm', file])
71
72 check_call(['git', 'add', target])
73
74 print("Merged what's new changes. Check the diff and commit the change.") No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now