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

Method run

Lib/pydoc.py:2213–2269  ·  view source on GitHub ↗
(self, callback, key=None, completer=None, onerror=None)

Source from the content-addressed store, hash-verified

2211 """An interruptible scanner that searches module synopses."""
2212
2213 def run(self, callback, key=None, completer=None, onerror=None):
2214 if key: key = key.lower()
2215 self.quit = False
2216 seen = {}
2217
2218 for modname in sys.builtin_module_names:
2219 if modname != '__main__':
2220 seen[modname] = 1
2221 if key is None:
2222 callback(None, modname, '')
2223 else:
2224 name = __import__(modname).__doc__ or ''
2225 desc = name.split('\n')[0]
2226 name = modname + ' - ' + desc
2227 if name.lower().find(key) >= 0:
2228 callback(None, modname, desc)
2229
2230 for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
2231 if self.quit:
2232 break
2233
2234 if key is None:
2235 callback(None, modname, '')
2236 else:
2237 try:
2238 spec = importer.find_spec(modname)
2239 except SyntaxError:
2240 # raised by tests for bad coding cookies or BOM
2241 continue
2242 loader = spec.loader
2243 if hasattr(loader, 'get_source'):
2244 try:
2245 source = loader.get_source(modname)
2246 except Exception:
2247 if onerror:
2248 onerror(modname)
2249 continue
2250 desc = source_synopsis(io.StringIO(source)) or ''
2251 if hasattr(loader, 'get_filename'):
2252 path = loader.get_filename(modname)
2253 else:
2254 path = None
2255 else:
2256 try:
2257 module = importlib._bootstrap._load(spec)
2258 except ImportError:
2259 if onerror:
2260 onerror(modname)
2261 continue
2262 desc = module.__doc__.splitlines()[0] if module.__doc__ else ''
2263 path = getattr(module,'__file__',None)
2264 name = modname + ' - ' + desc
2265 if name.lower().find(key) >= 0:
2266 callback(path, modname, desc)
2267
2268 if completer:
2269 completer()
2270

Callers

nothing calls this directly

Calls 13

__import__Function · 0.85
source_synopsisFunction · 0.85
completerFunction · 0.85
_loadMethod · 0.80
callbackFunction · 0.70
onerrorFunction · 0.70
lowerMethod · 0.45
splitMethod · 0.45
findMethod · 0.45
find_specMethod · 0.45
get_sourceMethod · 0.45
get_filenameMethod · 0.45

Tested by

no test coverage detected