当前位置: 首页>>代码示例>>Python>>正文


Python AstroidManager.project_from_files方法代码示例

本文整理汇总了Python中astroid.manager.AstroidManager.project_from_files方法的典型用法代码示例。如果您正苦于以下问题:Python AstroidManager.project_from_files方法的具体用法?Python AstroidManager.project_from_files怎么用?Python AstroidManager.project_from_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astroid.manager.AstroidManager的用法示例。


在下文中一共展示了AstroidManager.project_from_files方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PyreverseAdapter

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]
class PyreverseAdapter(Run):
    """Integrate with pyreverse by overriding its CLI Run class to
    create diagram definitions that can be passed to a writer."""

    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = AstroidManager()
        self.register_options_provider(self.manager)
        self.args = self.load_command_line_configuration()

    def run(self):
        if not self.args:
            print(self.help())
            return
        # Insert current working directory to the python path to recognize
        # dependencies to local modules even if cwd is not in the PYTHONPATH.
        sys.path.insert(0, os.getcwd())
        try:
            project = self.manager.project_from_files(self.args)
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        return diadefs
开发者ID:cb109,项目名称:pyplantuml,代码行数:29,代码来源:adapter.py

示例2: Run

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]
class Run(ConfigurationMixIn):
    """base class providing common behaviour for pyreverse commands"""

    options = OPTIONS

    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = AstroidManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        sys.exit(self.run(args))

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print self.help()
            return 1
        # insert current working directory to the python path to recognize
        # dependencies to local modules even if cwd is not in the PYTHONPATH
        sys.path.insert(0, os.getcwd())
        try:
            project = self.manager.project_from_files(args)
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        if self.config.output_format == "vcg":
            writer.VCGWriter(self.config).write(diadefs)
        else:
            writer.DotWriter(self.config).write(diadefs)
        return 0
开发者ID:JacobNinja,项目名称:exercism-analysis,代码行数:36,代码来源:main.py

示例3: parse

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]
    def parse(self):
        manager = AstroidManager()
        project = manager.project_from_files(list(self.file_paths),
                            func_wrapper=astroid_ignore_modname_wrapper)

        # First collect all definitions (e.g. module X, function foo) before
        # trying to relate one definition with another (e.g. module X depends on
        # module Y)
        DefsVisitor(self.modelers).visit(project)
        RelationsVisitor(self.modelers).visit(project)
开发者ID:qdamian,项目名称:dissect,代码行数:12,代码来源:source_code_parser.py

示例4: PylintUCRBuilder

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]
class PylintUCRBuilder(ConfigurationMixIn,IdGeneratorMixIn):
    
    options = OPTIONS
    _out_file = None
    
    def __init__(self, args,out_file='test.xml'):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        IdGeneratorMixIn.__init__(self)
        insert_default_options()
        self.manager = AstroidManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self._out_file = out_file
        self.run(args)
        pass
    
    def run(self, args):
        project = self.manager.project_from_files(args)
        linker = Linker(project, tag=True)
        handler = DiadefsHandler(self.config)
        diadefs = handler.get_diadefs(project, linker)
        root = etree.Element("Classes")
        classes = None
        for diagram in diadefs:
            if diagram.TYPE == 'class':
                classes = diagram
        class_map = {}
        class_nodes = []
        for c in classes.objects:
            ''' First pass - id generation '''
            c_id = str(self.generate_id())
            node = etree.Element("Class",name=c.title,id=c_id,label=c.node.root().name)
            if class_map.has_key(c.title):
                print "Duplicate class name - ",c.title
            else:
                class_map[c.title] = c_id
            root.append(node)
            class_nodes.append((c,node))
        attr_num = 0
        typed_attrs = 0
        for c, node in class_nodes:
            ''' Second pass - linking '''
            attr_num += len(c.attrs)
            for a in c.attrs:
                a_data =  [w.strip() for w in a.split(':')]
                found_attr = False
                attr_node = etree.Element('Attr',name=a_data[0])
                if (len(a_data) > 1):
                    types = [w.strip() for w in a_data[1].split(',')]
                    for t in types:
                        if class_map.has_key(t):
                            print "InnerType!"
                            found_attr = True
                            type_node = etree.Element('CommonType', id=class_map[a_data[1]],name=a_data[1])
                            attr_node.append(type_node)
                if found_attr:
                    typed_attrs += 1
                node.append(attr_node)
            #mapper[obj] = node
        print "Numbers of all attributes in project: ", attr_num
        print "Numbers of typed attributes in project: ", typed_attrs
        print "Percentage: ", typed_attrs*1.0/attr_num
        print "Writing ", self._out_file
        f = open(self._out_file,'w')
        f.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True))
        f.close()
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:68,代码来源:builder.py

示例5: AstroidManagerTC

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]
class AstroidManagerTC(TestCase):
    def setUp(self):
        self.manager = AstroidManager()
        self.manager.astroid_cache.clear()

    def test_ast_from_module(self):
        import unittest

        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.pure_python, True)
        import time

        astroid = self.manager.ast_from_module(time)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_class(self):
        astroid = self.manager.ast_from_class(int)
        self.assertEqual(astroid.name, "int")
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object)
        self.assertEqual(astroid.name, "object")
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn("__setattr__", astroid)

    def _test_ast_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop("mypypa", None)
        archive_path = join(DATA, archive)
        sys.path.insert(0, archive_path)
        try:
            module = self.manager.ast_from_module_name("mypypa")
            self.assertEqual(module.name, "mypypa")
            self.assertTrue(module.file.endswith("%s/mypypa" % archive), module.file)
        finally:
            # remove the module, else after importing egg, we don't get the zip
            if "mypypa" in self.manager.astroid_cache:
                del self.manager.astroid_cache["mypypa"]
                del self.manager._mod_file_cache[("mypypa", None)]
            if archive_path in sys.path_importer_cache:
                del sys.path_importer_cache[archive_path]
            sys.path = origpath

    def test_ast_from_module_name_egg(self):
        self._test_ast_from_zip("MyPyPa-0.1.0-py2.5.egg")

    def test_ast_from_module_name_zip(self):
        self._test_ast_from_zip("MyPyPa-0.1.0-py2.5.zip")

    def test_from_directory(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, "data")
        self.assertEqual(obj.name, "data")
        self.assertEqual(obj.path, join(DATA, "__init__.py"))

    def test_project_node(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, "data")
        expected = set(
            ["SSL1", "__init__", "all", "appl", "format", "module", "module2", "noendingnewline", "nonregr", "notall"]
        )
        expected = [
            "data",
            "data.SSL1",
            "data.SSL1.Connection1",
            "data.absimport",
            "data.all",
            "data.appl",
            "data.appl.myConnection",
            "data.email",
            "data.format",
            "data.module",
            "data.module2",
            "data.noendingnewline",
            "data.nonregr",
            "data.notall",
        ]
        self.assertListEqual(sorted(k for k in list(obj.keys())), expected)

    def test_do_not_expose_main(self):
        obj = self.manager.ast_from_module_name("__main__")
        self.assertEqual(obj.name, "__main__")
        self.assertEqual(list(obj.items()), [])
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:83,代码来源:unittest_manager.py

示例6: AstroidManagerTC

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]
class AstroidManagerTC(TestCase):
    def setUp(self):
        self.manager = AstroidManager()
        self.manager.astroid_cache.clear()

    def test_ast_from_module(self):
        import unittest
        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.pure_python, True)
        import time
        astroid = self.manager.ast_from_module(time)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_class(self):
        astroid = self.manager.ast_from_class(int)
        self.assertEqual(astroid.name, 'int')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object)
        self.assertEqual(astroid.name, 'object')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn('__setattr__', astroid)

    def _test_ast_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop('mypypa', None)
        archive_path = join(DATA, archive)
        sys.path.insert(0, archive_path)
        try:
            module = self.manager.ast_from_module_name('mypypa')
            self.assertEqual(module.name, 'mypypa')
            self.assertTrue(module.file.endswith('%s/mypypa' % archive),
                            module.file)
        finally:
            # remove the module, else after importing egg, we don't get the zip
            if 'mypypa' in self.manager.astroid_cache:
                del self.manager.astroid_cache['mypypa']
                del self.manager._mod_file_cache[('mypypa', None)]
            if archive_path in sys.path_importer_cache:
                del sys.path_importer_cache[archive_path]
            sys.path = origpath

    def test_ast_from_module_name_egg(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_ast_from_module_name_zip(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.zip')

    def test_from_directory(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
        self.assertEqual(obj.name, 'data')
        self.assertEqual(obj.path, join(DATA, '__init__.py'))

    def test_project_node(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
        expected = set(['SSL1', '__init__', 'all', 'appl', 'format', 'module',
                        'module2', 'noendingnewline', 'nonregr', 'notall'])
        expected = ['data', 'data.SSL1', 'data.SSL1.Connection1',
                    'data.absimport', 'data.all',
                    'data.appl', 'data.appl.myConnection', 'data.email', 'data.format',
                    'data.module', 'data.module2', 'data.noendingnewline',
                    'data.nonregr', 'data.notall']
        self.assertListEqual(sorted(k for k in obj.keys()), expected)

    def test_do_not_expose_main(self):
      obj = self.manager.ast_from_module_name('__main__')
      self.assertEqual(obj.name, '__main__')
      self.assertEqual(obj.items(), [])
开发者ID:Launcelot,项目名称:nupic-linux64,代码行数:70,代码来源:unittest_manager.py

示例7: AstroidManagerTC

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]

#.........这里部分代码省略.........
            if archive_path in sys.path_importer_cache:
                del sys.path_importer_cache[archive_path]
            sys.path = origpath

    def test_ast_from_module_name_egg(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_ast_from_module_name_zip(self):
        self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.zip')

    def test_zip_import_data(self):
        """check if zip_import_data works"""
        filepath = self.datapath('MyPyPa-0.1.0-py2.5.zip/mypypa')
        astroid = self.manager.zip_import_data(filepath)
        self.assertEqual(astroid.name, 'mypypa')

    def test_zip_import_data_without_zipimport(self):
        """check if zip_import_data return None without zipimport"""
        self.assertEqual(self.manager.zip_import_data('path'), None)

    def test_file_from_module(self):
        """check if the unittest filepath is equals to the result of the method"""
        import unittest
        if PY3K:
            unittest_file = unittest.__file__
        else:
            unittest_file = unittest.__file__[:-1]
        self.assertEqual(unittest_file,
                        self.manager.file_from_module_name('unittest', None))

    def test_file_from_module_name_astro_building_exception(self):
        """check if the method launch a exception with a wrong module name"""
        self.assertRaises(AstroidBuildingException, self.manager.file_from_module_name, 'unhandledModule', None)

    def test_ast_from_module(self):
        import unittest
        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.pure_python, True)
        import time
        astroid = self.manager.ast_from_module(time)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_module_cache(self):
        """check if the module is in the cache manager"""
        import unittest
        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.name, 'unittest')
        self.assertIn('unittest', self.manager.astroid_cache)

    def test_ast_from_class(self):
        astroid = self.manager.ast_from_class(int)
        self.assertEqual(astroid.name, 'int')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object)
        self.assertEqual(astroid.name, 'object')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn('__setattr__', astroid)

    def test_ast_from_class_with_module(self):
        """check if the method works with the module name"""
        astroid = self.manager.ast_from_class(int, int.__module__)
        self.assertEqual(astroid.name, 'int')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object, object.__module__)
        self.assertEqual(astroid.name, 'object')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn('__setattr__', astroid)

    def test_ast_from_class_attr_error(self):
        """give a wrong class at the ast_from_class method"""
        self.assertRaises(AstroidBuildingException, self.manager.ast_from_class, None)

    def test_from_directory(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
        self.assertEqual(obj.name, 'data')
        self.assertEqual(obj.path, join(DATA, '__init__.py'))

    def test_project_node(self):
        obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
        expected = set(['SSL1', '__init__', 'all', 'appl', 'format', 'module',
                        'module2', 'noendingnewline', 'nonregr', 'notall'])
        expected = [
            'data', 'data.SSL1', 'data.SSL1.Connection1',
            'data.absimport', 'data.all',
            'data.appl', 'data.appl.myConnection', 'data.email',
            'data.find_test',
            'data.find_test.module',
            'data.find_test.module2',
            'data.find_test.noendingnewline',
            'data.find_test.nonregr',
            'data.format',
            'data.lmfp',
            'data.lmfp.foo',
            'data.module',
            'data.module1abs', 'data.module1abs.core',
            'data.module2', 'data.noendingnewline',
            'data.nonregr', 'data.notall']
        self.assertListEqual(sorted(k for k in list(obj.keys())), expected)
开发者ID:Stronhold,项目名称:Mario,代码行数:104,代码来源:unittest_manager.py

示例8: AstroidManagerTest

# 需要导入模块: from astroid.manager import AstroidManager [as 别名]
# 或者: from astroid.manager.AstroidManager import project_from_files [as 别名]

#.........这里部分代码省略.........
    def test_ast_from_module(self):
        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.pure_python, True)
        import time
        astroid = self.manager.ast_from_module(time)
        self.assertEqual(astroid.pure_python, False)

    def test_ast_from_module_cache(self):
        """check if the module is in the cache manager"""
        astroid = self.manager.ast_from_module(unittest)
        self.assertEqual(astroid.name, 'unittest')
        self.assertIn('unittest', self.manager.astroid_cache)

    def test_ast_from_class(self):
        astroid = self.manager.ast_from_class(int)
        self.assertEqual(astroid.name, 'int')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object)
        self.assertEqual(astroid.name, 'object')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn('__setattr__', astroid)

    def test_ast_from_class_with_module(self):
        """check if the method works with the module name"""
        astroid = self.manager.ast_from_class(int, int.__module__)
        self.assertEqual(astroid.name, 'int')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)

        astroid = self.manager.ast_from_class(object, object.__module__)
        self.assertEqual(astroid.name, 'object')
        self.assertEqual(astroid.parent.frame().name, BUILTINS)
        self.assertIn('__setattr__', astroid)

    def test_ast_from_class_attr_error(self):
        """give a wrong class at the ast_from_class method"""
        self.assertRaises(AstroidBuildingException, self.manager.ast_from_class, None)

    def test_from_directory(self):
        obj = self.manager.project_from_files([resources.find('data')], _silent_no_wrap, 'data')
        self.assertEqual(obj.name, 'data')
        self.assertEqual(obj.path, os.path.abspath(resources.find('data/__init__.py')))

    def test_project_node(self):
        obj = self.manager.project_from_files([resources.find('data')], _silent_no_wrap, 'data')
        expected = [
            'data', 
            'data.SSL1', 
            'data.SSL1.Connection1',
            'data.absimp',
            'data.absimp.sidepackage',
            'data.absimp.string',
            'data.absimport', 
            'data.all',
            'data.appl', 
            'data.appl.myConnection',
            'data.clientmodule_test',
            'data.descriptor_crash', 
            'data.email',
            'data.find_test',
            'data.find_test.module',
            'data.find_test.module2',
            'data.find_test.noendingnewline',
            'data.find_test.nonregr',
            'data.format',
            'data.lmfp',
            'data.lmfp.foo',
            'data.module',
            'data.module1abs', 
            'data.module1abs.core',
            'data.module2', 
            'data.noendingnewline',
            'data.nonregr',
            'data.notall',
            'data.package',
            'data.package.absimport',
            'data.package.hello',
            'data.package.import_package_subpackage_module',
            'data.package.subpackage',
            'data.package.subpackage.module',
            'data.recursion',
            'data.suppliermodule_test',
            'data.unicode_package',
            'data.unicode_package.core']
        self.assertListEqual(sorted(obj.keys()), expected)

    def testFailedImportHooks(self):
        def hook(modname):
            if modname == 'foo.bar':
                return unittest
            else:
                raise AstroidBuildingException()

        with self.assertRaises(AstroidBuildingException):
            self.manager.ast_from_module_name('foo.bar')
        self.manager.register_failed_import_hook(hook)
        self.assertEqual(unittest, self.manager.ast_from_module_name('foo.bar'))
        with self.assertRaises(AstroidBuildingException):
            self.manager.ast_from_module_name('foo.bar.baz')
        del self.manager._failed_import_hooks[0]
开发者ID:Titulacion-Sistemas,项目名称:PythonTitulacion-EV,代码行数:104,代码来源:unittest_manager.py


注:本文中的astroid.manager.AstroidManager.project_from_files方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。