Returns a list containing the names of all the modules available in the folders of the pythonpath. ip.db['rootmodules_cache'] maps sys.path entries to list of modules.
()
| 105 | |
| 106 | |
| 107 | def get_root_modules(): |
| 108 | """ |
| 109 | Returns a list containing the names of all the modules available in the |
| 110 | folders of the pythonpath. |
| 111 | |
| 112 | ip.db['rootmodules_cache'] maps sys.path entries to list of modules. |
| 113 | """ |
| 114 | ip = get_ipython() |
| 115 | if ip is None: |
| 116 | # No global shell instance to store cached list of modules. |
| 117 | # Don't try to scan for modules every time. |
| 118 | return list(sys.builtin_module_names) |
| 119 | |
| 120 | rootmodules_cache = ip.db.get('rootmodules_cache', {}) |
| 121 | rootmodules = list(sys.builtin_module_names) |
| 122 | start_time = time() |
| 123 | store = False |
| 124 | for path in sys.path: |
| 125 | try: |
| 126 | modules = rootmodules_cache[path] |
| 127 | except KeyError: |
| 128 | modules = module_list(path) |
| 129 | try: |
| 130 | modules.remove('__init__') |
| 131 | except ValueError: |
| 132 | pass |
| 133 | if path not in ('', '.'): # cwd modules should not be cached |
| 134 | rootmodules_cache[path] = modules |
| 135 | if time() - start_time > TIMEOUT_STORAGE and not store: |
| 136 | store = True |
| 137 | print("\nCaching the list of root modules, please wait!") |
| 138 | print("(This will only be done once - type '%rehashx' to " |
| 139 | "reset cache!)\n") |
| 140 | sys.stdout.flush() |
| 141 | if time() - start_time > TIMEOUT_GIVEUP: |
| 142 | print("This is taking too long, we give up.\n") |
| 143 | return [] |
| 144 | rootmodules.extend(modules) |
| 145 | if store: |
| 146 | ip.db['rootmodules_cache'] = rootmodules_cache |
| 147 | rootmodules = list(set(rootmodules)) |
| 148 | return rootmodules |
| 149 | |
| 150 | |
| 151 | def is_importable(module, attr, only_modules): |
no test coverage detected