MCPcopy Index your code
hub / github.com/ipython/ipython / get_root_modules

Function get_root_modules

IPython/core/completerlib.py:108–152  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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

Callers 1

module_completionFunction · 0.85

Calls 5

get_ipythonFunction · 0.90
module_listFunction · 0.85
getMethod · 0.80
removeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…