-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from pytest-dev/release-3.11.0
Release 3.11.0
- Loading branch information
Showing
4 changed files
with
77 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
""" | ||
Generates the release notes for the latest release, in Markdown. | ||
Convert CHANGELOG.rst to Markdown, and extracts just the latest release. | ||
Writes to ``scripts/latest-release-notes.md``, which can be | ||
used with https://github.com/softprops/action-gh-release. | ||
1. Extracts the latest release from the CHANGELOG.rst file. | ||
2. Converts it to Markdown using pypandoc. | ||
3. Writes to ``scripts/latest-release-notes.md``, which can be | ||
used with https://github.com/softprops/action-gh-release. | ||
""" | ||
from pathlib import Path | ||
|
||
import pypandoc | ||
|
||
this_dir = Path(__file__).parent | ||
rst_text = (this_dir.parent / "CHANGELOG.rst").read_text(encoding="UTF-8") | ||
md_text = pypandoc.convert_text( | ||
rst_text, "md", format="rst", extra_args=["--wrap=preserve"] | ||
) | ||
|
||
output_lines = [] | ||
first_heading_found = False | ||
for line in md_text.splitlines(): | ||
if line.startswith("# "): | ||
# Skip the first section (normally # Releases). | ||
pass | ||
elif line.startswith("## "): | ||
# First second-level section, note it and skip the text, | ||
# as we are only interested in the individual release items. | ||
if first_heading_found: | ||
capture = False | ||
for line in rst_text.splitlines(): | ||
# Only start capturing after the latest release section. | ||
if line.startswith("-------"): | ||
capture = not capture | ||
if not capture: | ||
# We only need to capture the latest release, so stop. | ||
break | ||
first_heading_found = True | ||
else: | ||
continue | ||
|
||
if capture: | ||
output_lines.append(line) | ||
|
||
# Drop last line, as it contains the previous release section title. | ||
del output_lines[-1] | ||
|
||
trimmed_rst = "\n".join(output_lines).strip() | ||
print(">>Trimmed RST follows:") | ||
print(trimmed_rst) | ||
print(">>Trimmed RST ends") | ||
|
||
md_text = pypandoc.convert_text( | ||
trimmed_rst, "md", format="rst", extra_args=["--wrap=preserve"] | ||
) | ||
print(">>Converted Markdown follows:") | ||
print(md_text) | ||
print(">>Converted Markdown ends") | ||
|
||
output_fn = this_dir / "latest-release-notes.md" | ||
output_fn.write_text("\n".join(output_lines), encoding="UTF-8") | ||
output_fn.write_text(md_text, encoding="UTF-8") | ||
print(output_fn, "generated.") |