Skip to content

Commit

Permalink
Ensure no warnings are found in the NEWS file before a given line number
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 14, 2024
1 parent 53cdea8 commit 0b9102b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/reusable-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ jobs:
python Doc/tools/check-warnings.py \
--annotate-diff '${{ env.branch_base }}' '${{ env.branch_pr }}' \
--fail-if-regression \
--fail-if-improved
--fail-if-improved \
--fail-if-news-nit 150
# This build doesn't use problem matchers or check annotations
build_doc_oldest_supported_sphinx:
Expand Down
24 changes: 24 additions & 0 deletions Doc/tools/check-warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ def fail_if_improved(
return 0


def fail_if_news_nit(warnings: list[str], threshold: int) -> int:
"""
Ensure no warnings are found in the NEWS file before a given line number.
"""
news_nits = (warning for warning in warnings if "NEWS" in warning)
found = 0
for nit in news_nits:
nit_line_number = int(nit.split(":")[1])
if nit_line_number <= threshold:
print(nit)
found += 1

return -1 if found else 0


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
Expand All @@ -258,6 +273,12 @@ def main(argv: list[str] | None = None) -> int:
action="store_true",
help="Fail if new files with no nits are found",
)
parser.add_argument(
"--fail-if-news-nit",
metavar="threshold",
type=int,
help="Fail if NEWS nit found before threshold line number",
)

args = parser.parse_args(argv)
if args.annotate_diff is not None and len(args.annotate_diff) > 2:
Expand Down Expand Up @@ -298,6 +319,9 @@ def main(argv: list[str] | None = None) -> int:
if args.fail_if_improved:
exit_code += fail_if_improved(files_with_expected_nits, files_with_nits)

if args.fail_if_news_nit:
exit_code += fail_if_news_nit(warnings, args.fail_if_news_nit)

return exit_code


Expand Down

0 comments on commit 0b9102b

Please sign in to comment.