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

Method find_sources_in_dir

mypy/find_sources.py:110–140  ·  view source on GitHub ↗
(self, path: str)

Source from the content-addressed store, hash-verified

108 return normalise_package_base(path) in self.explicit_package_bases
109
110 def find_sources_in_dir(self, path: str) -> list[BuildSource]:
111 sources = []
112
113 seen: set[str] = set()
114 names = sorted(self.fscache.listdir(path), key=keyfunc)
115 for name in names:
116 # Skip certain names altogether
117 if name in ("__pycache__", "site-packages", "node_modules") or name.startswith("."):
118 continue
119 subpath = os.path.join(path, name)
120
121 if matches_exclude(subpath, self.exclude, self.fscache, self.verbosity >= 2):
122 continue
123 if self.exclude_gitignore and matches_gitignore(
124 subpath, self.fscache, self.verbosity >= 2
125 ):
126 continue
127
128 if self.fscache.isdir(subpath):
129 sub_sources = self.find_sources_in_dir(subpath)
130 if sub_sources:
131 seen.add(name)
132 sources.extend(sub_sources)
133 else:
134 stem, suffix = os.path.splitext(name)
135 if stem not in seen and suffix in PY_EXTENSIONS:
136 seen.add(stem)
137 module, base_dir = self.crawl_up(subpath)
138 sources.append(BuildSource(subpath, module, None, base_dir))
139
140 return sources
141
142 def crawl_up(self, path: str) -> tuple[str, str]:
143 """Given a .py[i] filename, return module and base directory.

Callers 2

create_source_listFunction · 0.95
find_sources_in_dirFunction · 0.80

Calls 13

crawl_upMethod · 0.95
matches_excludeFunction · 0.90
matches_gitignoreFunction · 0.90
BuildSourceClass · 0.90
setClass · 0.85
sortedFunction · 0.85
extendMethod · 0.80
appendMethod · 0.80
listdirMethod · 0.45
startswithMethod · 0.45
joinMethod · 0.45
isdirMethod · 0.45

Tested by 1

find_sources_in_dirFunction · 0.64