def _sub_modules_dict(self): names = {} paths = self.paths file_names = chain.from_iterable(os.listdir(path) for path in paths) mods = [file_name.rpartition('.')[0] if '.' in file_name else file_name for file_name in file_names] for name in mods: names[name] = imports.SubModuleName(self, name) return names
def _sub_modules_dict(self): """ Lists modules in the directory of this module (if this module is a package). """ path = self.tree_node.path names = {} if path is not None and path.endswith(os.path.sep + '__init__.py'): mods = pkgutil.iter_modules([os.path.dirname(path)]) for module_loader, name, is_pkg in mods: # It's obviously a relative import to the current module. names[name] = imports.SubModuleName(self, name) # TODO add something like this in the future, its cleaner than the # import hacks. # ``os.path`` is a hardcoded exception, because it's a # ``sys.modules`` modification. # if str(self.name) == 'os': # names.append(Name('path', parent_context=self)) return names