From 0b9102b2181da72095b6a70d3066802ad35937c0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:32:32 +0200 Subject: [PATCH] Ensure no warnings are found in the NEWS file before a given line number --- .github/workflows/reusable-docs.yml | 3 ++- Doc/tools/check-warnings.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-docs.yml b/.github/workflows/reusable-docs.yml index cea8f93d67b29c1..2e0a7be364a828b 100644 --- a/.github/workflows/reusable-docs.yml +++ b/.github/workflows/reusable-docs.yml @@ -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: diff --git a/Doc/tools/check-warnings.py b/Doc/tools/check-warnings.py index 122c9ed641d711a..64b51f5e8c9cf34 100644 --- a/Doc/tools/check-warnings.py +++ b/Doc/tools/check-warnings.py @@ -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( @@ -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: @@ -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