Skip to content

Commit 034cf0c

Browse files
authored
Docs: Ensure no warnings are found in the NEWS file before a given line number (#119221)
1 parent e188527 commit 034cf0c

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

.github/workflows/reusable-docs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ jobs:
6262
python Doc/tools/check-warnings.py \
6363
--annotate-diff '${{ env.branch_base }}' '${{ env.branch_pr }}' \
6464
--fail-if-regression \
65-
--fail-if-improved
65+
--fail-if-improved \
66+
--fail-if-new-news-nit
6667
6768
# This build doesn't use problem matchers or check annotations
6869
build_doc_oldest_supported_sphinx:

Doc/tools/check-warnings.py

+40
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from pathlib import Path
1414
from typing import TextIO
1515

16+
# Fail if NEWS nit found before this line number
17+
NEWS_NIT_THRESHOLD = 200
18+
1619
# Exclude these whether they're dirty or clean,
1720
# because they trigger a rebuild of dirty files.
1821
EXCLUDE_FILES = {
@@ -245,6 +248,32 @@ def fail_if_improved(
245248
return 0
246249

247250

251+
def fail_if_new_news_nit(warnings: list[str], threshold: int) -> int:
252+
"""
253+
Ensure no warnings are found in the NEWS file before a given line number.
254+
"""
255+
news_nits = (
256+
warning
257+
for warning in warnings
258+
if "/build/NEWS:" in warning
259+
)
260+
261+
# Nits found before the threshold line
262+
new_news_nits = [
263+
nit
264+
for nit in news_nits
265+
if int(nit.split(":")[1]) <= threshold
266+
]
267+
268+
if new_news_nits:
269+
print("\nError: new NEWS nits:\n")
270+
for warning in new_news_nits:
271+
print(warning)
272+
return -1
273+
274+
return 0
275+
276+
248277
def main(argv: list[str] | None = None) -> int:
249278
parser = argparse.ArgumentParser()
250279
parser.add_argument(
@@ -264,6 +293,14 @@ def main(argv: list[str] | None = None) -> int:
264293
action="store_true",
265294
help="Fail if new files with no nits are found",
266295
)
296+
parser.add_argument(
297+
"--fail-if-new-news-nit",
298+
metavar="threshold",
299+
type=int,
300+
nargs="?",
301+
const=NEWS_NIT_THRESHOLD,
302+
help="Fail if new NEWS nit found before threshold line number",
303+
)
267304

268305
args = parser.parse_args(argv)
269306
if args.annotate_diff is not None and len(args.annotate_diff) > 2:
@@ -304,6 +341,9 @@ def main(argv: list[str] | None = None) -> int:
304341
if args.fail_if_improved:
305342
exit_code += fail_if_improved(files_with_expected_nits, files_with_nits)
306343

344+
if args.fail_if_new_news_nit:
345+
exit_code += fail_if_new_news_nit(warnings, args.fail_if_new_news_nit)
346+
307347
return exit_code
308348

309349

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Fix race condition in free-threaded build where :meth:`list.extend` could expose
2-
uninitialied memory to concurrent readers.
1+
Fix race condition in free-threaded build where :meth:`!list.extend` could
2+
expose uninitialised memory to concurrent readers.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Fixed handling in :meth:`inspect.signature.bind` of keyword arguments having
1+
Fixed handling in :meth:`inspect.Signature.bind` of keyword arguments having
22
the same name as positional-only arguments when a variadic keyword argument
33
(e.g. ``**kwargs``) is present.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Suppress all :exc:`OSError` exceptions from :meth:`pathlib.Path.exists` and
22
``is_*()`` methods, rather than a selection of more common errors. The new
33
behaviour is consistent with :func:`os.path.exists`, :func:`os.path.isdir`,
4-
etc. Use :meth:`Path.stat` to retrieve the file status without suppressing
5-
exceptions.
4+
etc. Use :meth:`pathlib.Path.stat` to retrieve the file status without
5+
suppressing exceptions.

0 commit comments

Comments
 (0)