Exemplo n.º 1
0
    def _connect(self):
        """Connects the nodes & edges of the graph together by examining who
        the requirements of each node and finding another node that will
        create said dependency.
        """
        if len(self._graph) == 0:
            return []
        if self._connected:
            return self._runners

        # Clear out all automatically added edges since we want to do a fresh
        # connections. Leave the manually connected ones intact so that users
        # still retain the dependencies they established themselves.
        def discard_edge_func(u, v, e_data):
            if e_data and e_data.get('reason') != 'manual':
                return True
            return False

        # Link providers to requirers.
        graph_utils.connect(self._graph, discard_func=discard_edge_func)

        # Now figure out the order so that we can give the runners there
        # optional item providers as well as figure out the topological run
        # order.
        run_order = dag.topological_sort(self._graph)
        run_stack = []
        for r in run_order:
            r.runs_before = list(reversed(run_stack))
            run_stack.append(r)
        self._runners = run_order
        self._connected = True
        return run_order
Exemplo n.º 2
0
    def _connect(self):
        """Infers and connects the edges of the given tasks by examining the
        associated tasks provides and requires attributes and connecting tasks
        that require items to tasks that produce said items.
        """

        # Disconnect all edges not manually created before we attempt to infer
        # them so that we don't retain edges that are invalid.
        def disconnect_non_user(u, v, e_data):
            if e_data and e_data.get('reason') != 'manual':
                return True
            return False

        # Link providers to requirers.
        graph_utils.connect(self._graph,
                            discard_func=disconnect_non_user)

        # Connect the successors & predecessors and related siblings
        for r in self._graph.nodes_iter():
            r._predecessors = []
            r._successors = []
            for (r2, _me) in self._graph.in_edges_iter([r]):
                r._predecessors.append(r2)
            for (_me, r2) in self._graph.out_edges_iter([r]):
                r._successors.append(r2)
            r.siblings = []
            for r2 in self._graph.nodes_iter():
                if r2 is r or r2 in r._predecessors or r2 in r._successors:
                    continue
                r._siblings.append(r2)