MCPcopy
hub / github.com/python/mypy / create_source_list

Function create_source_list

mypy/find_sources.py:27–55  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

25
26
27def 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
58def keyfunc(name: str) -> tuple[bool, int, str]:

Callers 6

collect_build_targetsFunction · 0.90
cmd_checkMethod · 0.90
cmd_recheckMethod · 0.90
process_optionsFunction · 0.90
find_sourcesFunction · 0.90
parse_sourcesMethod · 0.90

Calls 10

crawl_upMethod · 0.95
find_sources_in_dirMethod · 0.95
FileSystemCacheClass · 0.90
BuildSourceClass · 0.90
SourceFinderClass · 0.85
InvalidSourceListClass · 0.85
appendMethod · 0.80
extendMethod · 0.80
endswithMethod · 0.45
isdirMethod · 0.45

Tested by 2

find_sourcesFunction · 0.72
parse_sourcesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…