MCPcopy Create free account
hub / github.com/ipython/ipython / module_list

Function module_list

IPython/core/completerlib.py:67–104  ·  view source on GitHub ↗

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

(path)

Source from the content-addressed store, hash-verified

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

Callers 2

get_root_modulesFunction · 0.85
try_importFunction · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected