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