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._inference_state.compiled_subprocess.get_builtin_module_names()] if search_path is None: search_path = self._sys_path_with_modifications(is_completion=True) for name in iter_module_names(self._inference_state, search_path): if in_module is None: n = ImportName(self._module_context, name) else: n = SubModuleName(in_module.as_context(), name) names.append(n) return names
def completion_names(self, inference_state, only_modules=False): """ :param only_modules: Indicates wheter it's possible to import a definition that is not defined in a module. """ if not self._infer_possible: return [] names = [] if self.import_path: # flask if self._str_import_path == ('flask', 'ext'): # List Flask extensions like ``flask_foo`` for mod in self._get_module_names(): modname = mod.string_name if modname.startswith('flask_'): extname = modname[len('flask_'):] names.append(ImportName(self._module_context, extname)) # Now the old style: ``flaskext.foo`` for dir in self._sys_path_with_modifications( is_completion=True): flaskext = os.path.join(dir, 'flaskext') if os.path.isdir(flaskext): names += self._get_module_names([flaskext]) values = self.follow() for value in values: # Non-modules are not completable. if value.api_type not in ('module', 'namespace'): # not a module continue if not value.is_compiled(): # sub_modules_dict is not implemented for compiled modules. names += value.sub_modules_dict().values() if not only_modules: from jedi.inference.gradual.conversion import convert_values both_values = values | convert_values(values) for c in both_values: for filter in c.get_filters(): names += filter.values() else: if self.level: # We only get here if the level cannot be properly calculated. names += self._get_module_names(self._fixed_sys_path) else: # This is just the list of global imports. names += self._get_module_names() return names