def sub_modules_dict(self): """ Lists modules in the directory of this module (if this module is a package). """ names = {} try: method = self.py__path__ except AttributeError: pass else: mods = iter_module_names(self.evaluator, method()) for name in mods: # It's obviously a relative import to the current module. names[name] = SubModuleName(self, name) # In the case of an import like `from x.` we don't need to # add all the variables, this is only about submodules. return names
def _get_module_names(self, search_path=None, in_module=None): """ Get the names of all modules in the search_path. This means file names and not names defined in the files. """ names = [] # add builtin module names if search_path is None and in_module is None: names += [ImportName(self.module_context, name) for name in self._evaluator.compiled_subprocess.get_builtin_module_names()] if search_path is None: search_path = self._sys_path_with_modifications() for name in iter_module_names(self._evaluator, search_path): if in_module is None: n = ImportName(self.module_context, name) else: n = SubModuleName(in_module, name) names.append(n) return names