Walk the repo and return all files that should have headers.
(root: Path)
| 170 | |
| 171 | |
| 172 | def discover_files(root: Path) -> list[Path]: |
| 173 | """Walk the repo and return all files that should have headers.""" |
| 174 | results = [] |
| 175 | |
| 176 | git_files = git_candidate_files(root) |
| 177 | if git_files is not None: |
| 178 | for rel in git_files: |
| 179 | path = root / rel |
| 180 | if not path.is_file(): |
| 181 | continue |
| 182 | if is_excluded(rel): |
| 183 | continue |
| 184 | if get_comment_style(rel) is not None: |
| 185 | results.append(path) |
| 186 | return sorted(results) |
| 187 | |
| 188 | for dirpath, dirnames, filenames in os.walk(root): |
| 189 | rel_dir = Path(dirpath).relative_to(root) |
| 190 | |
| 191 | # Prune excluded directories (modifying dirnames in-place). |
| 192 | dirnames[:] = [d for d in dirnames if not is_excluded(rel_dir / d)] |
| 193 | |
| 194 | for fname in filenames: |
| 195 | fpath = Path(dirpath) / fname |
| 196 | rel = fpath.relative_to(root) |
| 197 | if is_excluded(rel): |
| 198 | continue |
| 199 | if get_comment_style(rel) is not None: |
| 200 | results.append(fpath) |
| 201 | |
| 202 | return sorted(results) |
| 203 | |
| 204 | |
| 205 | # --------------------------------------------------------------------------- |
no test coverage detected