taken from the source code of help('modules') https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Lib/pydoc.py#L2178
()
| 221 | |
| 222 | |
| 223 | def scan_modules(): |
| 224 | """taken from the source code of help('modules') |
| 225 | |
| 226 | https://github.com/python/cpython/blob/63298930fb531ba2bb4f23bc3b915dbf1e17e9e1/Lib/pydoc.py#L2178""" |
| 227 | modules = {} |
| 228 | |
| 229 | def callback(path, modname, desc, modules=modules): |
| 230 | if modname and modname[-9:] == ".__init__": |
| 231 | modname = modname[:-9] + " (package)" |
| 232 | if modname.find(".") < 0: |
| 233 | modules[modname] = 1 |
| 234 | |
| 235 | def onerror(modname): |
| 236 | callback(None, modname, None) |
| 237 | |
| 238 | with warnings.catch_warnings(): |
| 239 | # ignore warnings from importing deprecated modules |
| 240 | warnings.simplefilter("ignore") |
| 241 | ModuleScanner().run(callback, onerror=onerror) |
| 242 | return list(modules.keys()) |
| 243 | |
| 244 | |
| 245 | def import_module(module_name): |
no test coverage detected