Walk paths and return all .py files, filtering out excludes.
(
paths: list[str],
excludes: list[str],
)
| 109 | |
| 110 | |
| 111 | def collect_python_files( |
| 112 | paths: list[str], |
| 113 | excludes: list[str], |
| 114 | ) -> list[Path]: |
| 115 | """Walk paths and return all .py files, filtering out excludes.""" |
| 116 | result: list[Path] = [] |
| 117 | exclude_parts = [e.replace("\\", "/").strip("/") for e in excludes] |
| 118 | |
| 119 | for p_str in paths: |
| 120 | p = Path(p_str) |
| 121 | if p.is_file() and p.suffix == ".py": |
| 122 | if not _is_excluded(p, exclude_parts): |
| 123 | result.append(p) |
| 124 | elif p.is_dir(): |
| 125 | for py_file in p.rglob("*.py"): |
| 126 | if not _is_excluded(py_file, exclude_parts): |
| 127 | result.append(py_file) |
| 128 | return result |
| 129 | |
| 130 | |
| 131 | def _is_excluded(path: Path, exclude_parts: list[str]) -> bool: |
no test coverage detected