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