Generates a new release announcement entry in the docs.
(version: str, template_name: str, doc_version: str)
| 16 | |
| 17 | |
| 18 | def announce(version: str, template_name: str, doc_version: str) -> None: |
| 19 | class="st">""class="st">"Generates a new release announcement entry in the docs."class="st">"" |
| 20 | class="cm"># Get our list of authors and co-authors. |
| 21 | stdout = check_output([class="st">"git", class="st">"describe", class="st">"--abbrev=0", class="st">"--tags"], encoding=class="st">"UTF-8") |
| 22 | last_version = stdout.strip() |
| 23 | rev_range = fclass="st">"{last_version}..HEAD" |
| 24 | |
| 25 | authors = check_output( |
| 26 | [class="st">"git", class="st">"log", rev_range, class="st">"--format=%aN"], encoding=class="st">"UTF-8" |
| 27 | ).splitlines() |
| 28 | |
| 29 | co_authors_output = check_output( |
| 30 | [class="st">"git", class="st">"log", rev_range, class="st">"--format=%(trailers:key=Co-authored-by) "], |
| 31 | encoding=class="st">"UTF-8", |
| 32 | ) |
| 33 | co_authors: list[str] = [] |
| 34 | for co_author_line in co_authors_output.splitlines(): |
| 35 | if m := re.search(rclass="st">"Co-authored-by: (.+?)<", co_author_line): |
| 36 | co_authors.append(m.group(1).strip()) |
| 37 | |
| 38 | contributors = { |
| 39 | name |
| 40 | for name in authors + co_authors |
| 41 | if not name.endswith(class="st">"[bot]") and name != class="st">"pytest bot" |
| 42 | } |
| 43 | |
| 44 | template_text = ( |
| 45 | Path(__file__).parent.joinpath(template_name).read_text(encoding=class="st">"UTF-8") |
| 46 | ) |
| 47 | |
| 48 | contributors_text = class="st">"\n".join(fclass="st">"* {name}" for name in sorted(contributors)) + class="st">"\n" |
| 49 | text = template_text.format( |
| 50 | version=version, contributors=contributors_text, doc_version=doc_version |
| 51 | ) |
| 52 | |
| 53 | target = Path(__file__).parent.joinpath(fclass="st">"../doc/en/announce/release-{version}.rst") |
| 54 | target.write_text(text, encoding=class="st">"UTF-8") |
| 55 | print(fclass="st">"{Fore.CYAN}[generate.announce] {Fore.RESET}Generated {target.name}") |
| 56 | |
| 57 | class="cm"># Update index with the new release entry |
| 58 | index_path = Path(__file__).parent.joinpath(class="st">"../doc/en/announce/index.rst") |
| 59 | lines = index_path.read_text(encoding=class="st">"UTF-8").splitlines() |
| 60 | indent = class="st">" " |
| 61 | for index, line in enumerate(lines): |
| 62 | if line.startswith(fclass="st">"{indent}release-"): |
| 63 | new_line = indent + target.stem |
| 64 | if line != new_line: |
| 65 | lines.insert(index, new_line) |
| 66 | index_path.write_text(class="st">"\n".join(lines) + class="st">"\n", encoding=class="st">"UTF-8") |
| 67 | print( |
| 68 | fclass="st">"{Fore.CYAN}[generate.announce] {Fore.RESET}Updated {index_path.name}" |
| 69 | ) |
| 70 | else: |
| 71 | print( |
| 72 | fclass="st">"{Fore.CYAN}[generate.announce] {Fore.RESET}Skip {index_path.name} (already contains release)" |
| 73 | ) |
| 74 | break |
| 75 |
no test coverage detected