Esempio n. 1
0
 def astng_from_file(self, filepath, modname=None, fallback=True):
     """given a module name, return the astng object"""
     try:
         filepath = get_source_file(filepath, include_no_ext=True)
         source = True
     except NoSourceFile:
         source = False
     if modname is None:
         modname = '.'.join(modpath_from_file(filepath))
     if modname in self._cache:
         return self._cache[modname]
     if source:
         try:
             from logilab.astng.builder import ASTNGBuilder
             return ASTNGBuilder(self).file_build(filepath, modname)
         except (SyntaxError, KeyboardInterrupt, SystemExit):
             raise
         except Exception, ex:
             raise
             if __debug__:
                 print 'error while building astng for', filepath
                 import traceback
                 traceback.print_exc()
             msg = 'Unable to load module %s (%s)' % (modname, ex)
             raise ASTNGBuildingException(msg), None, sys.exc_info()[-1]
Esempio n. 2
0
 def astng_from_file(self,
                     filepath,
                     modname=None,
                     fallback=True,
                     source=False):
     """given a module name, return the astng object"""
     try:
         filepath = get_source_file(filepath, include_no_ext=True)
         source = True
     except NoSourceFile:
         pass
     if modname is None:
         try:
             modname = '.'.join(modpath_from_file(filepath))
         except ImportError:
             modname = filepath
     if modname in self.astng_cache:
         return self.astng_cache[modname]
     if source:
         from logilab.astng.builder import ASTNGBuilder
         return ASTNGBuilder(self).file_build(filepath, modname)
     elif fallback and modname:
         return self.astng_from_module_name(modname)
     raise ASTNGBuildingException('unable to get astng for file %s' %
                                  filepath)
Esempio n. 3
0
 def astng_from_file(self, filepath, modname=None, fallback=True):
     """given a module name, return the astng object"""
     try:
         filepath = get_source_file(filepath, include_no_ext=True)
         source = True
     except NoSourceFile:
         source = False
     if modname is None:
         modname = '.'.join(modpath_from_file(filepath))
     if modname in self._cache:
         return self._cache[modname]
     if source:
         try:
             from logilab.astng.builder import ASTNGBuilder
             return ASTNGBuilder(self).file_build(filepath, modname)
         except (SyntaxError, KeyboardInterrupt, SystemExit):
             raise
         except Exception, ex:
             raise
             if __debug__:
                 print 'error while building astng for', filepath
                 import traceback
                 traceback.print_exc()
             msg = 'Unable to load module %s (%s)' % (modname, ex)
             raise ASTNGBuildingException(msg), None, sys.exc_info()[-1]
Esempio n. 4
0
 def ast_from_file(self, filepath, modname=None, fallback=True, source=False):
     """given a module name, return the astroid object"""
     try:
         filepath = get_source_file(filepath, include_no_ext=True)
         source = True
     except NoSourceFile:
         pass
     if modname is None:
         try:
             modname = '.'.join(modpath_from_file(filepath))
         except ImportError:
             modname = filepath
     if modname in self.astroid_cache and self.astroid_cache[modname].file == filepath:
         return self.astroid_cache[modname]
     if source:
         from astroid.builder import AstroidBuilder
         return AstroidBuilder(self).file_build(filepath, modname)
     elif fallback and modname:
         return self.ast_from_module_name(modname)
     raise AstroidBuildingException('unable to get astroid for file %s' %
                                  filepath)
Esempio n. 5
0
 def test(self):
     from os import path
     self.assertEqual(modutils.get_source_file(path.__file__),
                      path.__file__.replace('.pyc', '.py'))
Esempio n. 6
0
 def test(self):
     from os import path
     self.assertEqual(modutils.get_source_file(path.__file__),
                      path.__file__.replace('.pyc', '.py'))