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