(argv: list[str] | None = None)
| 104 | |
| 105 | |
| 106 | def main(argv: list[str] | None = None) -> int: |
| 107 | parser = argparse.ArgumentParser( |
| 108 | description="Check Python files for sys.path modification calls.", |
| 109 | ) |
| 110 | parser.add_argument( |
| 111 | "paths", |
| 112 | nargs="+", |
| 113 | help="Files or directories to check", |
| 114 | ) |
| 115 | parser.add_argument( |
| 116 | "--exclude", |
| 117 | nargs="*", |
| 118 | default=[], |
| 119 | help="Substrings to exclude from file paths", |
| 120 | ) |
| 121 | args = parser.parse_args(argv) |
| 122 | |
| 123 | files = collect_python_files(args.paths, args.exclude) |
| 124 | |
| 125 | total_violations = 0 |
| 126 | for path in files: |
| 127 | try: |
| 128 | source = path.read_text(encoding="utf-8", errors="replace") |
| 129 | except OSError: |
| 130 | continue |
| 131 | if not _SYS_PATH_RE.search(source): |
| 132 | continue |
| 133 | violations = check_file(str(path), source) |
| 134 | for line_no, message in violations: |
| 135 | print(f"{path}:{line_no}: {message}") |
| 136 | total_violations += 1 |
| 137 | |
| 138 | return 1 if total_violations > 0 else 0 |
| 139 | |
| 140 | |
| 141 | if __name__ == "__main__": |
no test coverage detected