MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / iter_modules

Method iter_modules

tools/python-3.11.9-amd64/Lib/pkgutil.py:228–266  ·  view source on GitHub ↗
(self, prefix='')

Source from the content-addressed store, hash-verified

226 return ImpLoader(fullname, file, filename, etc)
227
228 def iter_modules(self, prefix=''):
229 if self.path is None or not os.path.isdir(self.path):
230 return
231
232 yielded = {}
233 import inspect
234 try:
235 filenames = os.listdir(self.path)
236 except OSError:
237 # ignore unreadable directories like import does
238 filenames = []
239 filenames.sort() # handle packages before same-named modules
240
241 for fn in filenames:
242 modname = inspect.getmodulename(fn)
243 if modname=='__init__' or modname in yielded:
244 continue
245
246 path = os.path.join(self.path, fn)
247 ispkg = False
248
249 if not modname and os.path.isdir(path) and '.' not in fn:
250 modname = fn
251 try:
252 dircontents = os.listdir(path)
253 except OSError:
254 # ignore unreadable directories like import does
255 dircontents = []
256 for fn in dircontents:
257 subname = inspect.getmodulename(fn)
258 if subname=='__init__':
259 ispkg = True
260 break
261 else:
262 continue # not a package
263
264 if modname and '.' not in modname:
265 yielded[modname] = 1
266 yield prefix + modname, ispkg
267
268
269class ImpLoader:

Callers 5

iter_importer_modulesFunction · 0.80
docmoduleMethod · 0.80
indexMethod · 0.80
docmoduleMethod · 0.80
get_all_fix_namesFunction · 0.80

Calls 4

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

Tested by

no test coverage detected