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