Run the script.
()
| 383 | |
| 384 | |
| 385 | def main(): |
| 386 | """Run the script.""" |
| 387 | parser = argparse.ArgumentParser( |
| 388 | description="Fix common flake8 and pycodestyle issues in Python files." |
| 389 | ) |
| 390 | parser.add_argument( |
| 391 | "paths", nargs="+", help="Paths to files or directories to process." |
| 392 | ) |
| 393 | parser.add_argument( |
| 394 | "--exclude", |
| 395 | nargs="+", |
| 396 | default=["__pycache__", ".git", "venv", "env", ".venv", ".env"], |
| 397 | help="Directories to exclude from processing.", |
| 398 | ) |
| 399 | parser.add_argument( |
| 400 | "--mode", |
| 401 | choices=["auto", "pycodestyle", "tools"], |
| 402 | default="auto", |
| 403 | help=( |
| 404 | "Mode of operation: 'auto' uses both methods, 'pycodestyle' uses " |
| 405 | "pycodestyle output parsing, 'tools' uses external formatting tools." |
| 406 | ), |
| 407 | ) |
| 408 | parser.add_argument( |
| 409 | "--no-black", action="store_true", help="Don't use black for formatting." |
| 410 | ) |
| 411 | parser.add_argument( |
| 412 | "--no-isort", action="store_true", help="Don't use isort for import sorting." |
| 413 | ) |
| 414 | parser.add_argument( |
| 415 | "--no-autopep8", |
| 416 | action="store_true", |
| 417 | help="Don't use autopep8 for PEP 8 compliance.", |
| 418 | ) |
| 419 | parser.add_argument( |
| 420 | "-v", "--verbose", action="store_true", help="Print verbose output." |
| 421 | ) |
| 422 | |
| 423 | args = parser.parse_args() |
| 424 | |
| 425 | # Check if pycodestyle is installed |
| 426 | if args.mode in ["auto", "pycodestyle"]: |
| 427 | try: |
| 428 | subprocess.run( |
| 429 | ["which", "pycodestyle"], |
| 430 | check=True, |
| 431 | stdout=subprocess.PIPE, |
| 432 | stderr=subprocess.PIPE, |
| 433 | ) |
| 434 | except subprocess.CalledProcessError: |
| 435 | print("Error: pycodestyle is not installed. Please install it using pip:") |
| 436 | print(" pip install pycodestyle") |
| 437 | if args.mode == "pycodestyle": |
| 438 | return 1 |
| 439 | print("Falling back to tools-only mode.") |
| 440 | args.mode = "tools" |
| 441 | |
| 442 | # For tools mode, check if required tools are installed |
no test coverage detected
searching dependent graphs…