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

Function module_list

IPython/core/completerlib.py:68–105  ·  view source on GitHub ↗

Return the list containing the names of the modules available in the given folder.

(path: str)

Source from the content-addressed store, hash-verified

66
67
68def module_list(path: str) -> List[str]:
69 """
70 Return the list containing the names of the modules available in the given
71 folder.
72 """
73 # sys.path has the cwd as an empty string, but isdir/listdir need it as '.'
74 if path == '':
75 path = '.'
76
77 # A few local constants to be used in loops below
78 pjoin = os.path.join
79
80 if os.path.isdir(path):
81 # Build a list of all files in the directory and all files
82 # in its subdirectories. For performance reasons, do not
83 # recurse more than one level into subdirectories.
84 files: List[str] = []
85 for root, dirs, nondirs in os.walk(path, followlinks=True):
86 subdir = root[len(path)+1:]
87 if subdir:
88 files.extend(pjoin(subdir, f) for f in nondirs)
89 dirs[:] = [] # Do not recurse into additional subdirectories.
90 else:
91 files.extend(nondirs)
92
93 else:
94 try:
95 files = list(zipimporter(path)._files.keys()) # type: ignore
96 except Exception:
97 files = []
98
99 # Build a list of modules which match the import_re regex.
100 modules = []
101 for f in files:
102 m = import_re.match(f)
103 if m:
104 modules.append(m.group('name'))
105 return list(set(modules))
106
107
108def get_root_modules():

Callers 2

get_root_modulesFunction · 0.85
try_importFunction · 0.85

Calls 3

keysMethod · 0.80
matchMethod · 0.80
groupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…