Skip to content

Commit

Permalink
[3.13] Docs: Ensure no warnings are found in the NEWS file before a g…
Browse files Browse the repository at this point in the history
…iven line number (pythonGH-119221)

(cherry picked from commit 034cf0c)

Co-authored-by: Hugo van Kemenade <[email protected]>
  • Loading branch information
hugovk committed May 20, 2024
1 parent 054f1af commit bc701a2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
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-new-news-nit
# This build doesn't use problem matchers or check annotations
build_doc_oldest_supported_sphinx:
Expand Down
40 changes: 40 additions & 0 deletions Doc/tools/check-warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
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 = {
Expand Down Expand Up @@ -245,6 +248,32 @@ def fail_if_improved(
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(
Expand All @@ -264,6 +293,14 @@ 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-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:
Expand Down Expand Up @@ -304,6 +341,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_new_news_nit:
exit_code += fail_if_new_news_nit(warnings, args.fail_if_new_news_nit)

return exit_code


Expand Down
2 changes: 2 additions & 0 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@


class ANSIColors:
BLUE = "\x1b[1;34m"
BOLD_GREEN = "\x1b[1;32m"
BOLD_MAGENTA = "\x1b[1;35m"
BOLD_RED = "\x1b[1;31m"
CYAN = "\x1b[36m"
GREEN = "\x1b[32m"
GREY = "\x1b[90m"
MAGENTA = "\x1b[35m"
Expand Down
2 changes: 1 addition & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _format_final_exc_line(etype, value, *, insert_final_newline=True, colorize=
if value is None or not valuestr:
line = f"{ANSIColors.BOLD_MAGENTA}{etype}{ANSIColors.RESET}{end_char}"
else:
line = f"{ANSIColors.BOLD_MAGENTA}{etype}{ANSIColors.RESET}: {ANSIColors.MAGENTA}{valuestr}{ANSIColors.RESET}{end_char}"
line = f"{ANSIColors.BOLD_MAGENTA}{etype}{ANSIColors.RESET}: {ANSIColors.CYAN}{valuestr}{ANSIColors.RESET}{end_char}"
else:
if value is None or not valuestr:
line = f"{etype}{end_char}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Fix race condition in free-threaded build where :meth:`list.extend` could expose
uninitialied memory to concurrent readers.
Fix race condition in free-threaded build where :meth:`!list.extend` could
expose uninitialised memory to concurrent readers.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Fixed handling in :meth:`inspect.signature.bind` of keyword arguments having
Fixed handling in :meth:`inspect.Signature.bind` of keyword arguments having
the same name as positional-only arguments when a variadic keyword argument
(e.g. ``**kwargs``) is present.

0 comments on commit bc701a2

Please sign in to comment.