style: add changelog checks

pull/1101/head
matejcik 4 years ago committed by matejcik
parent 2c8e5f527b
commit 91da49266c

@ -9,9 +9,9 @@ PY_FILES = $(shell find . -type f -name '*.py' | grep -f ./tools/style.py.incl
C_FILES = $(shell find . -type f -name '*.[ch]' | grep -f ./tools/style.c.include | grep -v -f ./tools/style.c.exclude )
style_check: pystyle_check cstyle_check ## run all style checks (C+Py)
style_check: pystyle_check cstyle_check changelog_check ## run all style checks (C+Py)
style: pystyle cstyle ## apply all code styles (C+Py)
style: pystyle cstyle changelog ## apply all code styles (C+Py)
pystyle_check: ## run code style check on application sources and tests
flake8 --version
@ -39,6 +39,12 @@ pystyle: ## apply code style on application sources and tests
@flake8 $(PY_FILES)
make -C python style
changelog_check: # check changelog format
./tools/linkify-changelogs.py --check
changelog: # fill out issue links in changelog
./tools/linkify-changelogs.py
cstyle_check: ## run code style check on low-level C code
clang-format --version
@echo [CLANG-FORMAT]

@ -19,8 +19,9 @@ DEFAULT_CHANGELOGS = ( # TODO replace with a wildcard?
)
def process_changelog(changelog_file):
def process_changelog(changelog_file, only_check=False):
links = {}
orig_links = {}
result_lines = []
with open(changelog_file, "r+") as changelog:
@ -28,12 +29,22 @@ def process_changelog(changelog_file):
m = LINK_RE.match(line)
if m: # line *starts with* issue identifier
# keep existing links as-is
links[int(m[1])] = line.replace(m[0] + ": ", "").strip()
orig_links[int(m[1])] = line.replace(m[0] + ": ", "").strip()
else:
for issue in LINK_RE.findall(line):
links[int(issue)] = ISSUE_URL.format(issue=issue)
result_lines.append(line)
if only_check:
missing_links = set(links.keys()) - set(orig_links.keys())
if missing_links:
click.echo(f"missing links: {missing_links}")
return False
else:
return True
links.update(orig_links)
changelog.seek(0)
changelog.truncate(0)
for line in result_lines:
@ -41,6 +52,8 @@ def process_changelog(changelog_file):
for marker, url in sorted(links.items()):
changelog.write(f"[#{marker}]: {url}\n")
return True
@click.command()
@click.argument(
@ -48,7 +61,8 @@ def process_changelog(changelog_file):
nargs=-1,
type=click.Path(exists=True, dir_okay=False, writable=True),
)
def cli(changelogs):
@click.option("--check", is_flag=True, help="Check for missing links, do not modify.")
def cli(changelogs, check):
"""Linkify changelog.
Find all occurences of "[#123]" in text, and add a Markdown link to the referenced
@ -59,9 +73,14 @@ def cli(changelogs):
if not changelogs:
changelogs = DEFAULT_CHANGELOGS
all_ok = True
for changelog in changelogs:
click.echo(f"Linkifying {changelog}...")
process_changelog(changelog)
click.echo(changelog)
if not process_changelog(changelog, check):
all_ok = False
if not all_ok:
raise click.ClickException("Some links are missing. Run `make style` to fix.")
if __name__ == "__main__":

Loading…
Cancel
Save