Run pycodestyle on the specified paths and return the output. Args: paths: List of file or directory paths to check. exclude: List of patterns to exclude. Returns: The output from pycodestyle.
(paths: List[str], exclude: Optional[List[str]] = None)
| 46 | |
| 47 | |
| 48 | def run_pycodestyle(paths: List[str], exclude: Optional[List[str]] = None) -> str: |
| 49 | """Run pycodestyle on the specified paths and return the output. |
| 50 | |
| 51 | Args: |
| 52 | paths: List of file or directory paths to check. |
| 53 | exclude: List of patterns to exclude. |
| 54 | |
| 55 | Returns: |
| 56 | The output from pycodestyle. |
| 57 | """ |
| 58 | exclude_str = ",".join(exclude) if exclude else "" |
| 59 | cmd = ["pycodestyle", "--show-source", "--show-pep8"] |
| 60 | |
| 61 | if exclude_str: |
| 62 | cmd.extend(["--exclude", exclude_str]) |
| 63 | |
| 64 | cmd.extend(paths) |
| 65 | |
| 66 | try: |
| 67 | result = subprocess.run( |
| 68 | cmd, |
| 69 | check=False, # Don't raise an exception if pycodestyle finds issues |
| 70 | capture_output=True, |
| 71 | text=True, |
| 72 | ) |
| 73 | return result.stdout |
| 74 | except subprocess.CalledProcessError as e: |
| 75 | print(f"Error running pycodestyle: {e}", file=sys.stderr) |
| 76 | return e.stdout if e.stdout else "" |
| 77 | |
| 78 | |
| 79 | def parse_pycodestyle_output(output: str) -> Dict[str, List[Dict[str, str]]]: |