From a list of source files/directories, makes a list of BuildSources. Raises InvalidSourceList on errors.
(
paths: Sequence[str],
options: Options,
fscache: FileSystemCache | None = None,
allow_empty_dir: bool = False,
)
| 25 | |
| 26 | |
| 27 | def create_source_list( |
| 28 | paths: Sequence[str], |
| 29 | options: Options, |
| 30 | fscache: FileSystemCache | None = None, |
| 31 | allow_empty_dir: bool = False, |
| 32 | ) -> list[BuildSource]: |
| 33 | """From a list of source files/directories, makes a list of BuildSources. |
| 34 | |
| 35 | Raises InvalidSourceList on errors. |
| 36 | """ |
| 37 | fscache = fscache or FileSystemCache() |
| 38 | finder = SourceFinder(fscache, options) |
| 39 | |
| 40 | sources = [] |
| 41 | for path in paths: |
| 42 | path = os.path.normpath(path) |
| 43 | if path.endswith(PY_EXTENSIONS): |
| 44 | # Can raise InvalidSourceList if a directory doesn't have a valid module name. |
| 45 | name, base_dir = finder.crawl_up(path) |
| 46 | sources.append(BuildSource(path, name, None, base_dir)) |
| 47 | elif fscache.isdir(path): |
| 48 | sub_sources = finder.find_sources_in_dir(path) |
| 49 | if not sub_sources and not allow_empty_dir: |
| 50 | raise InvalidSourceList(f"There are no .py[i] files in directory '{path}'") |
| 51 | sources.extend(sub_sources) |
| 52 | else: |
| 53 | mod = os.path.basename(path) if options.scripts_are_modules else None |
| 54 | sources.append(BuildSource(path, mod, None)) |
| 55 | return sources |
| 56 | |
| 57 | |
| 58 | def keyfunc(name: str) -> tuple[bool, int, str]: |
searching dependent graphs…