()
| 59 | |
| 60 | |
| 61 | def main() -> int: |
| 62 | parser = argparse.ArgumentParser() |
| 63 | parser.add_argument("paths", nargs="*", default=["."], help="Files/directories to scan") |
| 64 | parser.add_argument("--line-length", type=int, default=88) |
| 65 | parser.add_argument("--check", action="store_true", help="Dry run; only show affected files") |
| 66 | args = parser.parse_args() |
| 67 | |
| 68 | files = unique_e501_files(args.paths) |
| 69 | if not files: |
| 70 | print("No E501 files found. Nothing to do.") |
| 71 | return 0 |
| 72 | |
| 73 | print(f"Found {len(files)} file(s) with E501.") |
| 74 | for f in files: |
| 75 | print(" -", f) |
| 76 | |
| 77 | if args.check: |
| 78 | return 0 |
| 79 | |
| 80 | for batch in chunked(files, 50): |
| 81 | run( |
| 82 | [ |
| 83 | "autopep8", |
| 84 | "--in-place", |
| 85 | "--aggressive", |
| 86 | f"--max-line-length={args.line_length}", |
| 87 | "--select=E501,W291,W292,W391", |
| 88 | *batch, |
| 89 | ] |
| 90 | ) |
| 91 | |
| 92 | run(["ruff", "check", *batch, "--fix", "--unsafe-fixes"], check=False) |
| 93 | run(["ruff", "format", *batch], check=False) |
| 94 | |
| 95 | after = len(unique_e501_files(args.paths)) |
| 96 | print(f"Remaining files with E501: {after}") |
| 97 | return 0 |
| 98 | |
| 99 | |
| 100 | if __name__ == "__main__": |
no test coverage detected