Skip to content

Commit b8ca8a6

Browse files
committed
Fix gen-release-notes.py script
Something changed in the RST->md conversion since the script was written, so fixed the script by trimming the releases based on the RST file instead, which we control.
1 parent d3e73f2 commit b8ca8a6

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

scripts/gen-release-notes.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,47 @@
11
"""
22
Generates the release notes for the latest release, in Markdown.
33
4-
Convert CHANGELOG.rst to Markdown, and extracts just the latest release.
5-
6-
Writes to ``scripts/latest-release-notes.md``, which can be
7-
used with https://github.com/softprops/action-gh-release.
4+
1. Extracts the latest release from the CHANGELOG.rst file.
5+
2. Converts it to Markdown using pypandoc.
6+
3. Writes to ``scripts/latest-release-notes.md``, which can be
7+
used with https://github.com/softprops/action-gh-release.
88
"""
99
from pathlib import Path
1010

1111
import pypandoc
1212

1313
this_dir = Path(__file__).parent
1414
rst_text = (this_dir.parent / "CHANGELOG.rst").read_text(encoding="UTF-8")
15-
md_text = pypandoc.convert_text(
16-
rst_text, "md", format="rst", extra_args=["--wrap=preserve"]
17-
)
1815

1916
output_lines = []
20-
first_heading_found = False
21-
for line in md_text.splitlines():
22-
if line.startswith("# "):
23-
# Skip the first section (normally # Releases).
24-
pass
25-
elif line.startswith("## "):
26-
# First second-level section, note it and skip the text,
27-
# as we are only interested in the individual release items.
28-
if first_heading_found:
17+
capture = False
18+
for line in rst_text.splitlines():
19+
# Only start capturing after the latest release section.
20+
if line.startswith("-------"):
21+
capture = not capture
22+
if not capture:
23+
# We only need to capture the latest release, so stop.
2924
break
30-
first_heading_found = True
31-
else:
25+
continue
26+
27+
if capture:
3228
output_lines.append(line)
3329

30+
# Drop last line, as it contains the previous release section title.
31+
del output_lines[-1]
32+
33+
trimmed_rst = "\n".join(output_lines).strip()
34+
print(">>Trimmed RST follows:")
35+
print(trimmed_rst)
36+
print(">>Trimmed RST ends")
37+
38+
md_text = pypandoc.convert_text(
39+
trimmed_rst, "md", format="rst", extra_args=["--wrap=preserve"]
40+
)
41+
print(">>Converted Markdown follows:")
42+
print(md_text)
43+
print(">>Converted Markdown ends")
44+
3445
output_fn = this_dir / "latest-release-notes.md"
35-
output_fn.write_text("\n".join(output_lines), encoding="UTF-8")
46+
output_fn.write_text(md_text, encoding="UTF-8")
3647
print(output_fn, "generated.")

0 commit comments

Comments
 (0)