| 65 | |
| 66 | |
| 67 | def list_files( |
| 68 | files: list[str], |
| 69 | recursive: bool = False, |
| 70 | extensions: Optional[list[str]] = None, |
| 71 | exclude: Optional[list[str]] = None, |
| 72 | ) -> list[str]: |
| 73 | if extensions is None: |
| 74 | extensions = [] |
| 75 | if exclude is None: |
| 76 | exclude = [] |
| 77 | |
| 78 | out: list[str] = [] |
| 79 | for file in files: |
| 80 | if recursive and os.path.isdir(file): |
| 81 | for dirpath, dnames, fnames in os.walk(file): |
| 82 | fpaths = [os.path.join(dirpath, fname) for fname in fnames] |
| 83 | for pattern in exclude: |
| 84 | # os.walk() supports trimming down the dnames list |
| 85 | # by modifying it in-place, |
| 86 | # to avoid unnecessary directory listings. |
| 87 | dnames[:] = [ |
| 88 | x |
| 89 | for x in dnames |
| 90 | if not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) |
| 91 | ] |
| 92 | fpaths = [x for x in fpaths if not fnmatch.fnmatch(x, pattern)] |
| 93 | for f in fpaths: |
| 94 | ext = os.path.splitext(f)[1][1:] |
| 95 | if ext in extensions: |
| 96 | out.append(f) |
| 97 | else: |
| 98 | out.append(file) |
| 99 | return out |
| 100 | |
| 101 | |
| 102 | def make_diff(file: str, original: list[str], reformatted: list[str]) -> list[str]: |