(argv: list[str] | None = None)
| 272 | |
| 273 | |
| 274 | def main(argv: list[str] | None = None) -> int: |
| 275 | parser = argparse.ArgumentParser() |
| 276 | parser.add_argument( |
| 277 | "--annotate-diff", |
| 278 | nargs="*", |
| 279 | metavar=("BASE_REF", "HEAD_REF"), |
| 280 | help="Add GitHub Actions annotations on the diff for warnings on " |
| 281 | "lines changed between the given refs (main and HEAD, by default)", |
| 282 | ) |
| 283 | parser.add_argument( |
| 284 | "--fail-if-regression", |
| 285 | action="store_true", |
| 286 | help="Fail if known-good files have warnings", |
| 287 | ) |
| 288 | parser.add_argument( |
| 289 | "--fail-if-improved", |
| 290 | action="store_true", |
| 291 | help="Fail if new files with no nits are found", |
| 292 | ) |
| 293 | parser.add_argument( |
| 294 | "--fail-if-new-news-nit", |
| 295 | metavar="threshold", |
| 296 | type=int, |
| 297 | nargs="?", |
| 298 | const=NEWS_NIT_THRESHOLD, |
| 299 | help="Fail if new NEWS nit found before threshold line number", |
| 300 | ) |
| 301 | |
| 302 | args = parser.parse_args(argv) |
| 303 | if args.annotate_diff is not None and len(args.annotate_diff) > 2: |
| 304 | parser.error( |
| 305 | "--annotate-diff takes between 0 and 2 ref args, not " |
| 306 | f"{len(args.annotate_diff)} {tuple(args.annotate_diff)}" |
| 307 | ) |
| 308 | exit_code = 0 |
| 309 | |
| 310 | wrong_directory_msg = "Must run this script from the repo root" |
| 311 | if not Path("Doc").exists() or not Path("Doc").is_dir(): |
| 312 | raise RuntimeError(wrong_directory_msg) |
| 313 | |
| 314 | warnings = ( |
| 315 | Path("Doc/sphinx-warnings.txt") |
| 316 | .read_text(encoding="UTF-8") |
| 317 | .splitlines() |
| 318 | ) |
| 319 | |
| 320 | cwd = str(Path.cwd()) + os.path.sep |
| 321 | files_with_nits = { |
| 322 | warning.removeprefix(cwd).split(":")[0] |
| 323 | for warning in warnings |
| 324 | if "Doc/" in warning |
| 325 | } |
| 326 | |
| 327 | with Path("Doc/tools/.nitignore").open(encoding="UTF-8") as clean_files: |
| 328 | files_with_expected_nits = { |
| 329 | filename.strip() |
| 330 | for filename in clean_files |
| 331 | if filename.strip() and not filename.startswith("#") |
no test coverage detected
searching dependent graphs…