コード例 #1
0
ファイル: manager.py プロジェクト: Marslo/VimConfig
 def ast_from_file(self, filepath, modname=None, fallback=True, source=False):
     """given a module name, return the astroid object"""
     try:
         filepath = modutils.get_source_file(filepath, include_no_ext=True)
         source = True
     except modutils.NoSourceFile:
         pass
     if modname is None:
         try:
             modname = '.'.join(modutils.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)
     if fallback and modname:
         return self.ast_from_module_name(modname)
     raise exceptions.AstroidBuildingError(
         'Unable to build an AST for {path}.', path=filepath)
コード例 #2
0
ファイル: manager.py プロジェクト: Stronhold/Mario
 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)
コード例 #3
0
 def test(self):
     filename = _get_file_from_object(os.path)
     self.assertEqual(modutils.get_source_file(os.path.__file__),
                      os.path.normpath(filename))
コード例 #4
0
ファイル: unittest_modutils.py プロジェクト: Stronhold/Mario
 def test(self):
     from os import path
     self.assertEqual(modutils.get_source_file(path.__file__),
                      path.normpath(path.__file__.replace('.pyc', '.py')))
コード例 #5
0
 def test(self):
     self.assertEqual(modutils.get_source_file(os.path.__file__),
                      os.path.normpath(os.path.__file__.replace('.pyc', '.py')))
コード例 #6
0
ファイル: unittest_modutils.py プロジェクト: upgradeQ/astroid
 def test(self):
     filename = _get_file_from_object(os.path)
     self.assertEqual(modutils.get_source_file(os.path.__file__),
                      os.path.normpath(filename))
コード例 #7
0
 def test(self):
     from os import path
     self.assertEqual(modutils.get_source_file(path.__file__),
                      path.normpath(path.__file__.replace('.pyc', '.py')))