Recursively finds files whose names match the given shell patterns.
(package_dir, patterns, excludes=())
| 142 | |
| 143 | |
| 144 | def find_data_files(package_dir, patterns, excludes=()): |
| 145 | """Recursively finds files whose names match the given shell patterns.""" |
| 146 | paths = set() |
| 147 | |
| 148 | def is_excluded(s): |
| 149 | for exclude in excludes: |
| 150 | if fnmatch.fnmatch(s, exclude): |
| 151 | return True |
| 152 | return False |
| 153 | |
| 154 | for directory, _, filenames in os.walk(package_dir): |
| 155 | if is_excluded(directory): |
| 156 | continue |
| 157 | for pattern in patterns: |
| 158 | for filename in fnmatch.filter(filenames, pattern): |
| 159 | # NB: paths must be relative to the package directory. |
| 160 | relative_dirpath = os.path.relpath(directory, package_dir) |
| 161 | full_path = os.path.join(relative_dirpath, filename) |
| 162 | if not is_excluded(full_path): |
| 163 | paths.add(full_path) |
| 164 | return list(paths) |
| 165 | |
| 166 | |
| 167 | setup( |
no test coverage detected
searching dependent graphs…