(argv: list[str] | None = None)
| 138 | |
| 139 | |
| 140 | def main(argv: list[str] | None = None) -> int: |
| 141 | parser = argparse.ArgumentParser( |
| 142 | description="Check Python files for subprocess.run with capture_output/PIPE.", |
| 143 | ) |
| 144 | parser.add_argument( |
| 145 | "paths", |
| 146 | nargs="+", |
| 147 | help="Files or directories to check", |
| 148 | ) |
| 149 | parser.add_argument( |
| 150 | "--exclude", |
| 151 | nargs="*", |
| 152 | default=[], |
| 153 | help="Substrings to exclude from file paths", |
| 154 | ) |
| 155 | args = parser.parse_args(argv) |
| 156 | |
| 157 | files = collect_python_files(args.paths, args.exclude) |
| 158 | |
| 159 | total_violations = 0 |
| 160 | for path in files: |
| 161 | try: |
| 162 | source = path.read_text(encoding="utf-8", errors="replace") |
| 163 | except OSError: |
| 164 | continue |
| 165 | if not _SUBPROCESS_RE.search(source): |
| 166 | continue |
| 167 | violations = check_file(str(path), source) |
| 168 | for line_no, message in violations: |
| 169 | print(f"{path}:{line_no}: {message}") |
| 170 | total_violations += 1 |
| 171 | |
| 172 | return 1 if total_violations > 0 else 0 |
| 173 | |
| 174 | |
| 175 | if __name__ == "__main__": |
no test coverage detected