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


Python ASTNGManager.project_from_files方法代码示例

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


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

示例1: PyreverseCommand

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import project_from_files [as 别名]
class PyreverseCommand(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 = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)

    def run(self, args):
        """checking arguments and run project"""
        if not 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(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)
开发者ID:OFFIS-Automation,项目名称:Framework,代码行数:35,代码来源:main.py

示例2: PyreverseCommand

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import project_from_files [as 别名]
class PyreverseCommand(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 = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)

    def run(self, args):
        """checking argmuents and run project"""
        if not args:
            print self.help()
            return
        project = self.manager.project_from_files(args, astng_wrapper)
        linker = Linker(project, tag=True)
        handler = DiadefsHandler(self.config)
        diadefs = handler.get_diadefs(project, linker)
        if self.config.output_format == "vcg":
            writer.VCGWriter(self.config).write(diadefs)
        else:
            writer.DotWriter(self.config).write(diadefs)
开发者ID:bmcharek,项目名称:opendata101-workshops,代码行数:28,代码来源:main.py

示例3: ASTNGHandler

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import project_from_files [as 别名]
class ASTNGHandler(ConfigurationMixIn):
    
    options = OPTIONS
    
    
    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        project = self.manager.project_from_files(args, astng_wrapper)
        self.project = project
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:15,代码来源:astng.py

示例4: ScannerCommand

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

    options = OPTIONS

    def __init__(self, view, args, callback):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        self.view = view
        self.callback = callback
        self.run(args)

    def run(self, args):
        """checking arguments and run project"""
        if not 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, args[0])
        sys.path.insert(0, os.getcwd())

        try:
            project = self.manager.project_from_files(args, black_list= \
                    map(os.path.relpath, BlackList.blacklist))
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        # filter just classes (not packages) for now
        diadefs = filter(lambda x: x.TYPE == 'class', diadefs)

        # update GUI
        Gdk.threads_enter()
        self.callback()
        writer.CanvasWriter(self.view, self.config).write(diadefs)
        Gdk.threads_leave()
开发者ID:jvorcak,项目名称:gpylint,代码行数:43,代码来源:scanner.py

示例5: UCRBuilder

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import project_from_files [as 别名]
class UCRBuilder(ConfigurationMixIn,DuckTypeHandler):
    # generate XML, describing classes of project
    
    options = OPTIONS
    
    # criteria for duck typing
    _criteria = None
    _out_file = None
    _project = None
    _good_gettatr = 0
    _bad_gettatr = 0
    # numbers of "ducks" in project (for complexity estimation)
    _all_ducks = 0
    # numbers of classes in project (for complexity estimation)
    _all_classes = 0
#     _found_ducks = 0
    _prob_used_classes = None
    _dbg_assattr_parents = None 
    _list_attrs = [attr for attr in dir([]) if not re.search('\A(?!_)',attr)]
    _list_methods = [attr for attr in dir([]) if re.search('\A(?!_)',attr)]
    _dict_attrs = [attr for attr in dir({}) if not re.search('\A(?!_)',attr)]
    _dict_methods = [attr for attr in dir({}) if re.search('\A(?!_)',attr)]
    _tuple_attrs = [attr for attr in dir(()) if not re.search('\A(?!_)',attr)]
    _tuple_methods = [attr for attr in dir(()) if re.search('\A(?!_)',attr)]
    _attr_iteration_cycles = 0
    _treshold = None
    _add_value = None
    
    def __init__(self, args,criteria='default',out_file='test.xml',treshold=None,add_value=False):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        self._add_value = add_value
        self._project = args[0]
        self._treshold = treshold
        self._out_file = out_file
        self._criteria = criteria
        self._dbg_assattr_parents = set([])
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)
    
    # Check if object is of standard complex type(dict, tuple or list)
    def _check_complex_type(self,attrs,methods):
        if(all(meth in self._list_methods for meth in methods) and
           all(attr in self._list_attrs for attr in attrs)):
            return 'List'
        elif(all(meth in self._dict_methods for meth in methods) and
             all(attr in self._dict_attrs for attr in attrs)):
            return 'Dict'
        elif(all(meth in self._tuple_methods for meth in methods) and
             all(attr in self._tuple_attrs for attr in attrs)):
            return 'Tuple'
        return None
    
    def get_duck_signature(self,duck):
        if(duck['complex_type']):
            if duck.has_key('element_signature'):
                # search for class of element is needed
                return set(duck['element_signature']['attrs'].keys()),set(duck['element_signature']['methods'].keys())
        return set(duck['attrs'].keys()), set(duck['methods'].keys())

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print self.help()
            return
        project = self.manager.project_from_files(args, astng_wrapper)
        self.project = project
        linker = ClassIRLinker(project)
        linker.visit(project)
        if self._criteria == 'capacity':
            found_ducks = {}
            bad_ducks = {}
            prob_used_classes = {}
            for t in numpy.arange(self._treshold,1,0.05):
                found_ducks[t] = 0
                bad_ducks[t] = 0
                prob_used_classes[t] = set([])
        else:
            prob_used_classes = set([])
            bad_ducks = 0
            found_ducks = 0
        ducks_num = len(list(linker.get_ducks()))
        count = 1
        dbg = set([])
        empty_ducks = 0
        """ Handle "duck" information and generate information about types """
        for current_class in linker.get_classes():
            for duck in current_class.cir_ducks.keys():
                print "Processing ", count, " duck of ",ducks_num
#                 print duck,current_class.cir_ducks[duck]
                count +=1
                duck_attrs, duck_methods = self.get_duck_signature(current_class.cir_ducks[duck])
                """ ignore empty ducks """
                if((not duck_attrs) and (not duck_methods)):
                    empty_ducks+=1
                    continue
                if not hasattr(current_class.cir_ducks[duck], 'complex_type'):
                    """ if duck is not detected  as complex type on previous stage (according to [],{} etc. usage)
#.........这里部分代码省略.........
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:103,代码来源:builder.py

示例6: ASTNGManagerTC

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import project_from_files [as 别名]
class ASTNGManagerTC(TestCase):
    def setUp(self):
        self.manager = ASTNGManager()
        self.manager.astng_cache.clear()

    def test_astng_from_module(self):
        import unittest
        astng = self.manager.astng_from_module(unittest)
        self.assertEqual(astng.pure_python, True)
        import time
        astng = self.manager.astng_from_module(time)
        self.assertEqual(astng.pure_python, False)

    def test_astng_from_class(self):
        astng = self.manager.astng_from_class(int)
        self.assertEqual(astng.name, 'int')
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)

        astng = self.manager.astng_from_class(object)
        self.assertEqual(astng.name, 'object')
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)
        self.failUnless('__setattr__' in astng)

    def _test_astng_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.astng_from_module_name('mypypa')
            self.assertEqual(module.name, 'mypypa')
            self.failUnless(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.astng_cache:
                del self.manager.astng_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_astng_from_module_name_egg(self):
        self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_astng_from_module_name_zip(self):
        self._test_astng_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.all',
                    'data.appl', 'data.appl.myConnection', '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.astng_from_module_name('__main__')
      self.assertEqual(obj.name, '__main__')
      self.assertEqual(list(obj.items()), [])
开发者ID:OFFIS-Automation,项目名称:Framework,代码行数:69,代码来源:unittest_manager.py

示例7: ASTNGManagerTC

# 需要导入模块: from logilab.astng.manager import ASTNGManager [as 别名]
# 或者: from logilab.astng.manager.ASTNGManager import project_from_files [as 别名]
class ASTNGManagerTC(TestCase):
    def setUp(self):
        self.manager = ASTNGManager()
        self.manager.astng_cache.clear()

    def test_astng_from_module(self):
        import unittest

        astng = self.manager.astng_from_module(unittest)
        self.assertEqual(astng.pure_python, True)
        import time

        astng = self.manager.astng_from_module(time)
        self.assertEqual(astng.pure_python, False)

    def test_astng_from_class(self):
        astng = self.manager.astng_from_class(int)
        self.assertEqual(astng.name, "int")
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)

        astng = self.manager.astng_from_class(object)
        self.assertEqual(astng.name, "object")
        self.assertEqual(astng.parent.frame().name, BUILTINS_NAME)
        self.failUnless("__setattr__" in astng)

    def _test_astng_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.astng_from_module_name("mypypa")
            self.assertEqual(module.name, "mypypa")
            self.failUnless(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.astng_cache:
                del self.manager.astng_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_astng_from_module_name_egg(self):
        self._test_astng_from_zip("MyPyPa-0.1.0-py2.5.egg")

    def test_astng_from_module_name_zip(self):
        self._test_astng_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.all",
            "data.appl",
            "data.appl.myConnection",
            "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.astng_from_module_name("__main__")
        self.assertEqual(obj.name, "__main__")
        self.assertEqual(obj.items(), [])
开发者ID:tomfitzhenry,项目名称:modern-python-example,代码行数:81,代码来源:unittest_manager.py

示例8: LogilabUCRBuilder

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

#.........这里部分代码省略.........
                        self._assigned_ducks+=1
                # DEBUG
                if (not node.parent.__class__.__name__ in self._dbg_assattr_parents):
                    self._dbg_assattr_parents |= Set([node.parent.__class__.__name__])
                    print node.parent.__class__.__name__
                    if(isinstance(node.parent, Tuple)):
                        print node.parent.as_string()
                # DEBUG END
                if(isinstance(node.parent, (Assign,AugAssign))):
                    if(isinstance(node.parent.value, (Tuple,Dict,List))):
                        duck_dict[node.attrname]['complex_type'] = node.parent.value.__class__.__name__ 
        for child in node.get_children():
            duck_dict = self._extract_duck_info(child,attrs,duck_dict)
        return duck_dict
    
    # Check if object is of standard complex type(dict, tuple or list)
    def _check_complex_type(self,attrs,methods):
        if(all(meth in self._list_methods for meth in methods) and
           all(attr in self._list_attrs for attr in attrs)):
            return 'List'
        elif(all(meth in self._dict_methods for meth in methods) and
             all(attr in self._dict_attrs for attr in attrs)):
            return 'Dict'
        elif(all(meth in self._tuple_methods for meth in methods) and
             all(attr in self._tuple_attrs for attr in attrs)):
            return 'Tuple'
        return None

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print self.help()
            return
        project = self.manager.project_from_files(args, astng_wrapper)
        self.project = project
        linker = NoInferLinker(project, tag=True)
        handler = DiadefsHandler(self.config)
        diadefs = handler.get_diadefs(project, linker)
        # Add inheritance information to nodes
        # csu_parents will contain links to all parents of class
        for rel in diadefs[-1].relationships['specialization']:
            if hasattr(rel.from_object, "csu_parents"):
                rel.from_object.csu_parents.append(rel.to_object)
            else:
                rel.from_object.csu_parents=[rel.to_object]
        bad_ducks = 0
        empty_ducks = 0
        # First pass for collecting "duck" information about fields 
        for obj in diadefs[-1].objects:
            self._compute_signature(obj)
            attr_names = [re.search('[^ :]*',s).group(0) for s in obj.attrs]
            self._all_attrs_num += len(Set(attr_names))
            attr_names+= [m.name for m in obj.methods]
            duck_dict = None
            for meth in obj.methods:
                # check self access in method and generate information about class attrs 
                if(self._process_candidates):
                    duck_dict =  self._extract_duck_info(meth,attr_names,duck_dict)
                self._processed_methods += 1
            # add duck information to classes
            obj.ducks=duck_dict
        successes = 0
        #Second pass  for processing "duck" information and generate information about types
        for current_class in diadefs[-1].objects:
            if (current_class.ducks is None):
                continue
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:70,代码来源:obsolete.py


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