def astng_from_module_name(self, modname, context_file=None): """given a module name, return the astng object""" old_cwd = os.getcwd() if context_file: os.chdir(dirname(context_file)) try: filepath = self.file_from_module_name(modname, context_file) if filepath is None or not is_python_source(filepath): try: module = load_module_from_name(modname) except ImportError, ex: msg = 'Unable to load module %s (%s)' % (modname, ex) raise ASTNGBuildingException(msg) return self.astng_from_module(module, modname) return self.astng_from_file(filepath, modname, fallback=False)
def astng_from_module_name(self, modname, context_file=None): """given a module name, return the astng object""" old_cwd = os.getcwd() if context_file: os.chdir(dirname(context_file)) try: filepath = self.file_from_module_name(modname, context_file) if filepath is None or not is_python_source(filepath): try: module = load_module_from_name(modname) except ImportError, ex: msg = 'Unable to load module %s (%s)' % (modname, ex) raise ASTNGBuildingException(msg) return self.astng_from_module(module, modname) return self.astng_from_file(filepath, modname, fallback=False)
def astng_from_module(self, module, modname=None): """given an imported module, return the astng object""" modname = modname or module.__name__ filepath = modname try: # some builtin modules don't have __file__ attribute filepath = module.__file__ if is_python_source(filepath): return self.astng_from_file(filepath, modname) except AttributeError: pass try: return self._cache[filepath] except KeyError: from clonedigger.logilab.astng.builder import ASTNGBuilder astng = ASTNGBuilder(self).module_build(module, modname) # update caches (filepath and astng.file are not necessarily the # same (.pyc pb)) self._cache[filepath] = self._cache[astng.file] = astng return astng
def astng_from_module(self, module, modname=None): """given an imported module, return the astng object""" modname = modname or module.__name__ filepath = modname try: # some builtin modules don't have __file__ attribute filepath = module.__file__ if is_python_source(filepath): return self.astng_from_file(filepath, modname) except AttributeError: pass try: return self._cache[filepath] except KeyError: from clonedigger.logilab.astng.builder import ASTNGBuilder astng = ASTNGBuilder(self).module_build(module, modname) # update caches (filepath and astng.file are not necessarily the # same (.pyc pb)) self._cache[filepath] = self._cache[astng.file] = astng return astng