Given a list of files and directories, return just files. If we are not passed a language, determine it. Filter out files that are not of that language :param list[str] raw_source_paths: file or directory paths :param str|None language: Input language :rtype: (list, str)
(raw_source_paths, language)
| 283 | |
| 284 | |
| 285 | def get_sources_and_language(raw_source_paths, language): |
| 286 | """ |
| 287 | Given a list of files and directories, return just files. |
| 288 | If we are not passed a language, determine it. |
| 289 | Filter out files that are not of that language |
| 290 | |
| 291 | :param list[str] raw_source_paths: file or directory paths |
| 292 | :param str|None language: Input language |
| 293 | :rtype: (list, str) |
| 294 | """ |
| 295 | |
| 296 | individual_files = [] |
| 297 | for source in sorted(raw_source_paths): |
| 298 | if os.path.isfile(source): |
| 299 | individual_files.append((source, True)) |
| 300 | continue |
| 301 | for root, _, files in os.walk(source): |
| 302 | for f in files: |
| 303 | individual_files.append((os.path.join(root, f), False)) |
| 304 | |
| 305 | if not individual_files: |
| 306 | raise AssertionError("No source files found from %r" % raw_source_paths) |
| 307 | logging.info("Found %d files from sources argument.", len(individual_files)) |
| 308 | |
| 309 | if not language: |
| 310 | language = determine_language(individual_files) |
| 311 | |
| 312 | sources = set() |
| 313 | for source, explicity_added in individual_files: |
| 314 | if explicity_added or source.endswith('.' + language): |
| 315 | sources.add(source) |
| 316 | else: |
| 317 | logging.info("Skipping %r which is not a %s file. " |
| 318 | "If this is incorrect, include it explicitly.", |
| 319 | source, language) |
| 320 | |
| 321 | if not sources: |
| 322 | raise AssertionError("Could not find any source files given {raw_source_paths} " |
| 323 | "and language {language}.") |
| 324 | |
| 325 | sources = sorted(list(sources)) |
| 326 | logging.info("Processing %d source file(s)." % (len(sources))) |
| 327 | for source in sources: |
| 328 | logging.info(" " + source) |
| 329 | |
| 330 | return sources, language |
| 331 | |
| 332 | |
| 333 | def make_file_group(tree, filename, extension): |
no test coverage detected