Walk paths and return all .py files, filtering out excludes.
(
paths: list[str],
excludes: list[str],
)
| 75 | |
| 76 | |
| 77 | def collect_python_files( |
| 78 | paths: list[str], |
| 79 | excludes: list[str], |
| 80 | ) -> list[Path]: |
| 81 | """Walk paths and return all .py files, filtering out excludes.""" |
| 82 | result: list[Path] = [] |
| 83 | exclude_parts = [e.replace("\\", "/").strip("/") for e in excludes] |
| 84 | |
| 85 | for p_str in paths: |
| 86 | p = Path(p_str) |
| 87 | if p.is_file() and p.suffix == ".py": |
| 88 | if not _is_excluded(p, exclude_parts): |
| 89 | result.append(p) |
| 90 | elif p.is_dir(): |
| 91 | for py_file in p.rglob("*.py"): |
| 92 | if not _is_excluded(py_file, exclude_parts): |
| 93 | result.append(py_file) |
| 94 | return result |
| 95 | |
| 96 | |
| 97 | def _is_excluded(path: Path, exclude_parts: list[str]) -> bool: |
no test coverage detected