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

Function _iter_file_finder_modules

Lib/pkgutil.py:128–166  ·  view source on GitHub ↗
(importer, prefix='')

Source from the content-addressed store, hash-verified

126
127# Implement a file walker for the normal importlib path hook
128def _iter_file_finder_modules(importer, prefix=''):
129 if importer.path is None or not os.path.isdir(importer.path):
130 return
131
132 yielded = {}
133 import inspect
134 try:
135 filenames = os.listdir(importer.path)
136 except OSError:
137 # ignore unreadable directories like import does
138 filenames = []
139 filenames.sort() # handle packages before same-named modules
140
141 for fn in filenames:
142 modname = inspect.getmodulename(fn)
143 if modname=='__init__' or modname in yielded:
144 continue
145
146 path = os.path.join(importer.path, fn)
147 ispkg = False
148
149 if not modname and os.path.isdir(path) and '.' not in fn:
150 modname = fn
151 try:
152 dircontents = os.listdir(path)
153 except OSError:
154 # ignore unreadable directories like import does
155 dircontents = []
156 for fn in dircontents:
157 subname = inspect.getmodulename(fn)
158 if subname=='__init__':
159 ispkg = True
160 break
161 else:
162 continue # not a package
163
164 if modname and '.' not in modname:
165 yielded[modname] = 1
166 yield prefix + modname, ispkg
167
168iter_importer_modules.register(
169 importlib.machinery.FileFinder, _iter_file_finder_modules)

Callers

nothing calls this directly

Calls 4

listdirMethod · 0.80
isdirMethod · 0.45
sortMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…