from pathlib import Path
from typing import TextIO
+# Fail if NEWS nit found before this line number
+NEWS_NIT_THRESHOLD = 200
+
# Exclude these whether they're dirty or clean,
# because they trigger a rebuild of dirty files.
EXCLUDE_FILES = {
return 0
+def fail_if_new_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 "/build/NEWS:" in warning
+ )
+
+ # Nits found before the threshold line
+ new_news_nits = [
+ nit
+ for nit in news_nits
+ if int(nit.split(":")[1]) <= threshold
+ ]
+
+ if new_news_nits:
+ print("\nError: new NEWS nits:\n")
+ for warning in new_news_nits:
+ print(warning)
+ return -1
+
+ return 0
+
+
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
action="store_true",
help="Fail if new files with no nits are found",
)
+ parser.add_argument(
+ "--fail-if-new-news-nit",
+ metavar="threshold",
+ type=int,
+ nargs="?",
+ const=NEWS_NIT_THRESHOLD,
+ help="Fail if new 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:
if args.fail_if_improved:
exit_code += fail_if_improved(files_with_expected_nits, files_with_nits)
+ if args.fail_if_new_news_nit:
+ exit_code += fail_if_new_news_nit(warnings, args.fail_if_new_news_nit)
+
return exit_code
Suppress all :exc:`OSError` exceptions from :meth:`pathlib.Path.exists` and
``is_*()`` methods, rather than a selection of more common errors. The new
behaviour is consistent with :func:`os.path.exists`, :func:`os.path.isdir`,
-etc. Use :meth:`Path.stat` to retrieve the file status without suppressing
-exceptions.
+etc. Use :meth:`pathlib.Path.stat` to retrieve the file status without
+suppressing exceptions.