MCPcopy Index your code
hub / github.com/python/cpython / find_all_submodules

Method find_all_submodules

Lib/modulefinder.py:274–300  ·  view source on GitHub ↗
(self, m)

Source from the content-addressed store, hash-verified

272 raise ImportError("No module named " + subname)
273
274 def find_all_submodules(self, m):
275 if not m.__path__:
276 return
277 modules = {}
278 # 'suffixes' used to be a list hardcoded to [".py", ".pyc"].
279 # But we must also collect Python extension modules - although
280 # we cannot separate normal dlls from Python extensions.
281 suffixes = []
282 suffixes += importlib.machinery.EXTENSION_SUFFIXES[:]
283 suffixes += importlib.machinery.SOURCE_SUFFIXES[:]
284 suffixes += importlib.machinery.BYTECODE_SUFFIXES[:]
285 for dir in m.__path__:
286 try:
287 names = os.listdir(dir)
288 except OSError:
289 self.msg(2, "can't list directory", dir)
290 continue
291 for name in names:
292 mod = None
293 for suff in suffixes:
294 n = len(suff)
295 if name[-n:] == suff:
296 mod = name[:-n]
297 break
298 if mod and mod != "__init__":
299 modules[mod] = mod
300 return modules.keys()
301
302 def import_module(self, partname, fqname, parent):
303 self.msgin(3, "import_module", partname, fqname, parent)

Callers 1

ensure_fromlistMethod · 0.95

Calls 3

msgMethod · 0.95
listdirMethod · 0.80
keysMethod · 0.45

Tested by

no test coverage detected