Пример #1
0
def rebuild_ast(tree, modname='', package=False):
    manager = AstroidManager()
    builder = AstroidBuilder(manager)
    rebuilder = TreeRebuilder(manager)
    module = rebuilder.visit_module(tree, modname=modname, package=package)
    module._from_nodes = rebuilder._from_nodes
    module._delayed_assattr = rebuilder._delayed_assattr
    module = builder._post_build(module, 'utf8')
    return module
Пример #2
0
 def _data_build(self, data, modname, path):
     """build tree node from data and add some informations"""
     # this method could be wrapped with a pickle/cache function
     node = parse(data + '\n')
     if path is not None:
         node_file = abspath(path)
     else:
         node_file = '<?>'
     if modname.endswith('.__init__'):
         modname = modname[:-9]
         package = True
     else:
         package = path and path.find('__init__.py') > -1 or False
     rebuilder = TreeRebuilder(self._manager)
     module = rebuilder.visit_module(node, modname, package)
     module.file = module.path = node_file
     module._from_nodes = rebuilder._from_nodes
     module._delayed_assattr = rebuilder._delayed_assattr
     return module
Пример #3
0
 def _data_build(self, data, modname, path):
     """build tree node from data and add some informations"""
     # this method could be wrapped with a pickle/cache function
     node = parse(data + '\n')
     if path is not None:
         node_file = abspath(path)
     else:
         node_file = '<?>'
     if modname.endswith('.__init__'):
         modname = modname[:-9]
         package = True
     else:
         package = path and path.find('__init__.py') > -1 or False
     rebuilder = TreeRebuilder(self._manager)
     module = rebuilder.visit_module(node, modname, package)
     module.file = module.path = node_file
     module._from_nodes = rebuilder._from_nodes
     module._delayed_assattr = rebuilder._delayed_assattr
     return module
Пример #4
0
 def _data_build(self, data, modname, path):
     """build tree node from data and add some informations"""
     # this method could be wrapped with a pickle/cache function
     try:
         node = parse(data + "\n")
     except TypeError as exc:
         raise AstroidBuildingException(exc)
     if path is not None:
         node_file = abspath(path)
     else:
         node_file = "<?>"
     if modname.endswith(".__init__"):
         modname = modname[:-9]
         package = True
     else:
         package = path and path.find("__init__.py") > -1 or False
     rebuilder = TreeRebuilder(self._manager)
     module = rebuilder.visit_module(node, modname, node_file, package)
     module._from_nodes = rebuilder._from_nodes
     module._delayed_assattr = rebuilder._delayed_assattr
     return module