|
| 1 | +#!/bin/env python3 |
| 2 | + |
1 | 3 | import itertools
|
2 | 4 | import os
|
3 | 5 | import re
|
| 6 | +import tomllib |
4 | 7 |
|
5 |
| -import toml |
6 | 8 | from git import GitCommandError, Repo
|
7 | 9 | from packaging.version import parse as parse_version
|
8 | 10 |
|
9 | 11 | # Read Towncrier settings
|
10 |
| -tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"] |
| 12 | +with open("pyproject.toml", "rb") as fp: |
| 13 | + tc_settings = tomllib.load(fp)["tool"]["towncrier"] |
11 | 14 |
|
12 | 15 | CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst")
|
13 | 16 | START_STRING = tc_settings.get(
|
|
21 | 24 | TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})")
|
22 | 25 |
|
23 | 26 |
|
| 27 | +# Build a regex to find the header of a changelog section. |
| 28 | +# It must have a single capture group to single out the version. |
| 29 | +# see help(re.split) for more info. |
24 | 30 | NAME_REGEX = r".*"
|
25 |
| -VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)" |
| 31 | +VERSION_REGEX = r"[0-9]+\.[0-9]+\.[0-9][0-9ab]*" |
| 32 | +VERSION_CAPTURE_REGEX = rf"({VERSION_REGEX})" |
26 | 33 | DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}"
|
27 | 34 | TITLE_REGEX = (
|
28 | 35 | "("
|
29 | 36 | + re.escape(
|
30 | 37 | TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
|
31 | 38 | )
|
32 | 39 | .replace("NAME_REGEX", NAME_REGEX)
|
| 40 | + .replace("VERSION_REGEX", VERSION_CAPTURE_REGEX, 1) |
33 | 41 | .replace("VERSION_REGEX", VERSION_REGEX)
|
34 | 42 | .replace("DATE_REGEX", DATE_REGEX)
|
35 | 43 | + ")"
|
36 | 44 | )
|
37 | 45 |
|
38 | 46 |
|
39 | 47 | def get_changelog(repo, branch):
|
40 |
| - return repo.git.show(f"{branch}:{CHANGELOG_FILE}") + "\n" |
| 48 | + branch_tc_settings = tomllib.loads(repo.git.show(f"{branch}:pyproject.toml"))["tool"][ |
| 49 | + "towncrier" |
| 50 | + ] |
| 51 | + branch_changelog_file = branch_tc_settings.get("filename", "NEWS.rst") |
| 52 | + return repo.git.show(f"{branch}:{branch_changelog_file}") + "\n" |
41 | 53 |
|
42 | 54 |
|
43 | 55 | def _tokenize_changes(splits):
|
@@ -89,7 +101,7 @@ def main():
|
89 | 101 | for change in main_changes:
|
90 | 102 | fp.write(change[1])
|
91 | 103 |
|
92 |
| - repo.git.commit("-m", "Update Changelog", "-m" "[noissue]", CHANGELOG_FILE) |
| 104 | + repo.git.commit("-m", "Update Changelog", CHANGELOG_FILE) |
93 | 105 |
|
94 | 106 |
|
95 | 107 | if __name__ == "__main__":
|
|
0 commit comments