Return a list of source files under 'root', where filenames end with any of the extensions in 'exts' (e.g., '.c.src', '.c', '.h'). Excludes directories whose names are in 'excludes'.
(root: Path, exts: set[str], excludes: set[str])
| 65 | return ("".join(out_parts), in_block) |
| 66 | |
| 67 | def iter_source_files(root: Path, exts: set[str], excludes: set[str]) -> list[Path]: |
| 68 | """ |
| 69 | Return a list of source files under 'root', where filenames end with any of the |
| 70 | extensions in 'exts' (e.g., '.c.src', '.c', '.h'). |
| 71 | Excludes directories whose names are in 'excludes'. |
| 72 | """ |
| 73 | results: list[Path] = [] |
| 74 | |
| 75 | for dirpath, dirnames, filenames in os.walk(root): |
| 76 | # Prune excluded directories |
| 77 | dirnames[:] = [d for d in dirnames if d not in excludes] |
| 78 | for fn in filenames: |
| 79 | # endswith handles mult-suffice patterns, e.g., .c.src |
| 80 | if any(fn.endswith(ext) for ext in exts): |
| 81 | results.append(Path(dirpath) / fn) |
| 82 | return results |
| 83 | |
| 84 | def build_func_rx(funcs: tuple[str, ...]) -> Pattern[str]: |
| 85 | return re.compile(r"(?<!\w)(?:" + "|".join(map(re.escape, funcs)) + r")(?!\w)") |