Example #1
0
    def aggregate_graph(mapper, ignore_external, exceptions, file_graph):
        assert (isinstance(mapper, AggregateMapper))
        pseudomodule_graph = MutableAttributeGraph()
        for edge in file_graph.edges():
            from_node = mapper.get_output_aggregate_for_individual(
                edge.get_from_node())
            if mapper.is_file_in_input_aggregates(edge.get_to_node()):
                to_node = mapper.get_output_aggregate_for_individual(
                    edge.get_to_node())
                if not (from_node == to_node or
                        (from_node, to_node) in exceptions):
                    pseudomodule_graph.add_edge_and_nodes(from_node, to_node)
                else:
                    pseudomodule_graph.add_node(from_node)
                    pseudomodule_graph.add_node(to_node)
            elif not ignore_external:
                to_node = edge.get_to_node()
                pseudomodule_graph.add_edge_and_nodes(from_node, to_node)
            else:
                pseudomodule_graph.add_node(from_node)

        # TODO warum wird das gemacht?
        for node in pseudomodule_graph.nodes_raw():
            pseudomodule_graph.set_node_attrs(node, {NodeAttributes.LABEL: ""})

        return pseudomodule_graph
 def get_cluster_dependency_graph(self, clustering_result,
                                  base_dependency_graph):
     """
     @param clustering_result: 
     @param base_dependency_graph: A BasicGraph whose nodes are the elements of the clusters.
     @return: An AttributeGraph whose nodes are groups of nodes of the base_dependency_graph according to 
     the clusters.
     """
     cluster_graph = MutableAttributeGraph()
     clusters = clustering_result.values()
     for cluster in clusters:
         pseudomodule = self.__to_pseudomodule_list(cluster)
         cluster_graph.set_node_attrs(
             self.__make_nodename(pseudomodule), {
                 NodeAttributes.GROUPED_NODES: pseudomodule,
                 NodeAttributes.LABEL: ""
             }, True)
     for cluster_pair in product(clusters, clusters):
         if cluster_pair[0] != cluster_pair[1]:
             pseudomodule_pair = map(self.__to_pseudomodule_list,
                                     cluster_pair)
             if any(
                     base_dependency_graph.has_edge(edge[0], edge[1])
                     for edge in product(pseudomodule_pair[0],
                                         pseudomodule_pair[1])):
                 cluster_graph.add_edge_and_nodes(
                     self.__make_nodename(pseudomodule_pair[0]),
                     self.__make_nodename(pseudomodule_pair[1]))
     return cluster_graph
 def test_filter_nothing_nonempty_graph_additional_module(self):
     full_graph = MutableAttributeGraph()
     full_graph.add_edge_and_nodes("a", "b")
     full_graph.add_edge_and_nodes("b", "c")
     full_graph.add_edge_and_nodes("d", "a")
     filtered_graph = DefaultDependencyFilter.filter_graph(
         full_graph.immutable(),
         dependency_filter_config=NullDependencyFilterConfiguration(),
         internal_modules=["a", "e"])
     self.assertEqual(["a", "b", "c", "d", "e"],
                      sorted(filtered_graph.node_names()))
     self.assertEqual(3, filtered_graph.edge_count())
Example #4
0
 def __test(self):
     description = GraphDescriptionImpl(description="Test",
                                        basename="test",
                                        section="test")
     graph = MutableAttributeGraph()
     graph.add_edge_and_nodes("a", "b")
     module_group_conf = config_module_group_conf(
         module_grouper=config_module_grouper())
     DependencyFilterOutputterTools.output_detail_and_overview_graph(
         graph=graph,
         module_group_conf=module_group_conf,
         outputter=config_dependency_filter_outputter(),
         description=description)
Example #5
0
 def graph_for_from_module(self, from_modules):
     if isinstance(from_modules, basestring):
         from_modules = (from_modules, )
     graph = MutableAttributeGraph()
     self.__graph = graph
     self.process_for_all_file_deps(lambda from_file, from_file_module, to_file, to_file_module: \
                                    graph.add_edge_and_nodes(from_file, to_file) if from_file_module in from_modules else None)
     self.__graph = None
     return graph
Example #6
0
    def filter_graph(full_graph, dependency_filter_config, internal_modules):
        """
        
        @param full_graph:
        @param dependency_filter_config:
        @param internal_modules: All internal modules are added to the graph even if they are not 
            connected to any other module. If the graph is focused on a particular module group, 
            this applies only if they belong to this module group.
        """
        graph = MutableAttributeGraph()
        for module in internal_modules:
            if not dependency_filter_config.skip_module(module) and not dependency_filter_config.skip_module_as_source(module):
                graph.add_node(module)
        for edge in full_graph.edges():
            source = str(edge.get_from_node())
            target = str(edge.get_to_node())
            if not (dependency_filter_config.skip_module(source) \
                    or dependency_filter_config.skip_module(target) \
                    or dependency_filter_config.skip_module_as_source(source) \
                    or dependency_filter_config.skip_module_as_target(target) \
                    or dependency_filter_config.skip_edge(source, target)):
                graph.add_edge_and_nodes(source, target)
            else:
                if dependency_filter_config.skip_module_as_source(source) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge source %s->%s", source, target)
                    graph.set_node_attrs(source, {NodeAttributes.SKIPPED_FROM_EDGE: True}, True)
                if dependency_filter_config.skip_module_as_target(target) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge target %s->%s", source, target)
                    graph.set_node_attrs(target, {NodeAttributes.SKIPPED_TO_EDGE: True}, True)

        if dependency_filter_config.focus_on_node_groups:
            node_grouper = dependency_filter_config.get_module_grouper()
            exception_func = lambda node: node_grouper.get_node_group_prefix(node) in dependency_filter_config.focus_on_node_groups
        else:
            exception_func = lambda node: False
        graph.delete_unconnected_nodes(exception_func)
        return graph
Example #7
0
class DefaultDependencyFilter(DependencyFilter):
    """
    This class is not intended to be subclassed.
    """
    
    _supports_grouping = True

    def __init__(self,
                 config,
                 module_list,
                 default_edge_attrs=dict(),
                 *args, **kwargs):
        assert isinstance(config, DependencyFilterConfiguration)
        self.__initial_config = config
        self.__full_graph = MutableAttributeGraph(default_edge_attrs=dict({EdgeAttributes.COLOR: "red"}))
        self.__logger = logging.getLogger(self.__class__.__module__)
        self.__module_list = module_list
        self.__graph = None

    def __get_module_list(self):
        return self.__module_list

    def _edges(self):
        warnings.warn("use _graph().edges()", DeprecationWarning)
        return self.__graph.edges()

#    def _config(self):
#        return self.__initial_config

#    def _graph(self):
#        return self.__graph

#    def set_node_size(self, node, height, width):
#        self.__graph.set_node_attrs(node, {NodeAttributes.HEIGHT: height,
#                                            NodeAttributes.WIDTH: width}, create=True)

#    def set_node_shape(self, node, shape):
#        self.__graph.set_node_attrs(node, {NodeAttributes.SHAPE: shape}, create=True)

    def dependency(self, source, target):
        self.__full_graph.add_edge_and_nodes(source, target)

    @staticmethod
    def filter_graph(full_graph, dependency_filter_config, internal_modules):
        """
        
        @param full_graph:
        @param dependency_filter_config:
        @param internal_modules: All internal modules are added to the graph even if they are not 
            connected to any other module. If the graph is focused on a particular module group, 
            this applies only if they belong to this module group.
        """
        graph = MutableAttributeGraph()
        for module in internal_modules:
            if not dependency_filter_config.skip_module(module) and not dependency_filter_config.skip_module_as_source(module):
                graph.add_node(module)
        for edge in full_graph.edges():
            source = str(edge.get_from_node())
            target = str(edge.get_to_node())
            if not (dependency_filter_config.skip_module(source) \
                    or dependency_filter_config.skip_module(target) \
                    or dependency_filter_config.skip_module_as_source(source) \
                    or dependency_filter_config.skip_module_as_target(target) \
                    or dependency_filter_config.skip_edge(source, target)):
                graph.add_edge_and_nodes(source, target)
            else:
                if dependency_filter_config.skip_module_as_source(source) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge source %s->%s", source, target)
                    graph.set_node_attrs(source, {NodeAttributes.SKIPPED_FROM_EDGE: True}, True)
                if dependency_filter_config.skip_module_as_target(target) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge target %s->%s", source, target)
                    graph.set_node_attrs(target, {NodeAttributes.SKIPPED_TO_EDGE: True}, True)

        if dependency_filter_config.focus_on_node_groups:
            node_grouper = dependency_filter_config.get_module_grouper()
            exception_func = lambda node: node_grouper.get_node_group_prefix(node) in dependency_filter_config.focus_on_node_groups
        else:
            exception_func = lambda node: False
        graph.delete_unconnected_nodes(exception_func)
        return graph

    def __color_nodes(self):
        warnings.warn("use a node decorator instead", DeprecationWarning)
        for node in self.__full_graph.node_names_iter():
            color = self.__initial_config.get_node_color(str(node))
            self.__graph.set_node_attrs(node, {NodeAttributes.FILL_COLOR: color})

    def __color_edges(self):
        # TODO besser in einem Decorator. Wird das überhaupt noch benutzt?
        for edge in self.__full_graph.edges():
            edge.set_attrs({EdgeAttributes.COLOR:
                            self.__initial_config.get_edge_color(str(edge.get_from_node()),
                                                         str(edge.get_to_node())
                                                         )})

    def postamble(self):
        #self.__color_nodes()
        self.__color_edges()
        graph = self.filter_graph(full_graph=self.__full_graph, 
                                  dependency_filter_config=self.__initial_config,
                                  internal_modules=self.__get_module_list())
        self.__graph = graph.immutable()

    def graph(self):
        #return self.__graph.immutable()
        return MutableAttributeGraph(graph=self.__graph)