def get_graph(self):
g = digraph()<EOL>scopes = dict((x.package_name, x) for x in self.scopes)<EOL>failure_nodes = set()<EOL>request_nodes = {}  <EOL>scope_nodes = {}  <EOL>node_color = "<STR_LIT>"<EOL>request_color = "<STR_LIT>"<EOL>solved_color = "<STR_LIT>"<EOL>node_fontsize = <NUM_LIT:10><EOL>counter = [<NUM_LIT:1>]<EOL>def _uid():<EOL><INDENT>id_ = counter[<NUM_LIT:0>]<EOL>counter[<NUM_LIT:0>] += <NUM_LIT:1><EOL>return "<STR_LIT>" % id_<EOL><DEDENT>def _add_edge(id1, id2, arrowsize=<NUM_LIT:0.5>):<EOL><INDENT>e = (id1, id2)<EOL>if g.has_edge(e):<EOL><INDENT>g.del_edge(e)<EOL><DEDENT>g.add_edge(e)<EOL>g.add_edge_attribute(e, ("<STR_LIT>", str(arrowsize)))<EOL>return e<EOL><DEDENT>def _add_extraction_merge_edge(id1, id2):<EOL><INDENT>e = _add_edge(id1, id2, <NUM_LIT:1>)<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL><DEDENT>def _add_conflict_edge(id1, id2):<EOL><INDENT>e = _add_edge(id1, id2, <NUM_LIT:1>)<EOL>g.set_edge_label(e, "<STR_LIT>")<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL><DEDENT>def _add_cycle_edge(id1, id2):<EOL><INDENT>e = _add_edge(id1, id2, <NUM_LIT:1>)<EOL>g.set_edge_label(e, "<STR_LIT>")<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL>g.add_edge_attribute(e, ("<STR_LIT>", "<STR_LIT>"))<EOL><DEDENT>def _add_reduct_edge(id1, id2, label):<EOL><INDENT>e = _add_edge(id1, id2, <NUM_LIT:1>)<EOL>g.set_edge_label(e, label)<EOL>g.add_edge_attribute(e, ("<STR_LIT>", node_fontsize))<EOL><DEDENT>def _add_node(label, color, style):<EOL><INDENT>attrs = [("<STR_LIT:label>", label),<EOL>("<STR_LIT>", node_fontsize),<EOL>("<STR_LIT>", color),<EOL>("<STR_LIT>", '<STR_LIT>' % style)]<EOL>id_ = _uid()<EOL>g.add_node(id_, attrs=attrs)<EOL>return id_<EOL><DEDENT>def _add_request_node(request, initial_request=False):<EOL><INDENT>id_ = request_nodes.get(request)<EOL>if id_ is not None:<EOL><INDENT>return id_<EOL><DEDENT>label = str(request)<EOL>if initial_request:<EOL><INDENT>color = request_color<EOL><DEDENT>else:<EOL><INDENT>color = node_color<EOL><DEDENT>id_ = _add_node(label, color, "<STR_LIT>")<EOL>request_nodes[request] = id_<EOL>return id_<EOL><DEDENT>def _add_scope_node(scope):<EOL><INDENT>id_ = scope_nodes.get(scope.package_name)<EOL>if id_ is not None:<EOL><INDENT>return id_<EOL><DEDENT>variant = scope._get_solved_variant()<EOL>if variant:<EOL><INDENT>label = str(variant)<EOL>color = solved_color<EOL>style = "<STR_LIT>"<EOL><DEDENT>elif scope.is_conflict:<EOL><INDENT>label = str(scope)<EOL>color = node_color<EOL>style = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>label = str(scope)<EOL>color = node_color<EOL>style = "<STR_LIT>"<EOL><DEDENT>id_ = _add_node(label, color, style)<EOL>scope_nodes[scope.package_name] = id_<EOL>return id_<EOL><DEDENT>def _add_reduct_node(request):<EOL><INDENT>return _add_node(str(request), node_color, "<STR_LIT>")<EOL><DEDENT>for request in self.solver.request_list:<EOL><INDENT>_add_request_node(request, True)<EOL><DEDENT>for scope in self.scopes:<EOL><INDENT>if scope.is_conflict:<EOL><INDENT>id1 = request_nodes.get(scope.package_request)<EOL>if id1 is not None:<EOL><INDENT>scope_nodes[scope.package_name] = id1<EOL>del request_nodes[scope.package_request]<EOL>continue<EOL><DEDENT><DEDENT>_add_scope_node(scope)<EOL><DEDENT>for request in self.solver.request_list:<EOL><INDENT>id1 = request_nodes.get(request)<EOL>if id1 is not None:<EOL><INDENT>id2 = scope_nodes.get(request.name)<EOL>if id2 is not None:<EOL><INDENT>_add_edge(id1, id2)<EOL><DEDENT><DEDENT><DEDENT>for scope in self.scopes:<EOL><INDENT>variant = scope._get_solved_variant()<EOL>if variant:<EOL><INDENT>id1 = scope_nodes[scope.package_name]<EOL>for request in variant.requires_list.requirements:<EOL><INDENT>id2 = _add_request_node(request)<EOL>_add_edge(id1, id2)<EOL><DEDENT><DEDENT><DEDENT>for (src_fam, _), dest_req in self.extractions.items():<EOL><INDENT>id1 = scope_nodes.get(src_fam)<EOL>if id1 is not None:<EOL><INDENT>id2 = _add_request_node(dest_req)<EOL>_add_edge(id1, id2)<EOL><DEDENT><DEDENT>extracted_fams = set(x[<NUM_LIT:1>] for x in self.extractions.keys())<EOL>for fam in extracted_fams:<EOL><INDENT>requests = [v for k, v in self.extractions.items() if k[<NUM_LIT:1>] == fam]<EOL>if len(requests) > <NUM_LIT:1>:<EOL><INDENT>reqlist = RequirementList(requests)<EOL>if not reqlist.conflict:<EOL><INDENT>merged_request = reqlist.get(fam)<EOL>for request in requests:<EOL><INDENT>if merged_request != request:<EOL><INDENT>id1 = _add_request_node(request)<EOL>id2 = _add_request_node(merged_request)<EOL>_add_extraction_merge_edge(id1, id2)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>fr = self.failure_reason<EOL>if fr:<EOL><INDENT>if isinstance(fr, DependencyConflicts):<EOL><INDENT>for conflict in fr.conflicts:<EOL><INDENT>id1 = _add_request_node(conflict.dependency)<EOL>id2 = scope_nodes.get(conflict.conflicting_request.name)<EOL>if id2 is None:<EOL><INDENT>id2 = _add_request_node(conflict.conflicting_request)<EOL><DEDENT>_add_conflict_edge(id1, id2)<EOL>failure_nodes.add(id1)<EOL>failure_nodes.add(id2)<EOL><DEDENT><DEDENT>elif isinstance(fr, TotalReduction):<EOL><INDENT>if len(fr.reductions) == <NUM_LIT:1>:<EOL><INDENT>reduct = fr.reductions[<NUM_LIT:0>]<EOL>id1 = scope_nodes[reduct.name]<EOL>id2 = _add_request_node(reduct.dependency)<EOL>id3 = scope_nodes[reduct.conflicting_request.name]<EOL>_add_edge(id1, id2)<EOL>_add_conflict_edge(id2, id3)<EOL>failure_nodes.add(id1)<EOL>failure_nodes.add(id2)<EOL>failure_nodes.add(id3)<EOL><DEDENT>else:<EOL><INDENT>for reduct in fr.reductions:<EOL><INDENT>id1 = scope_nodes[reduct.name]<EOL>id2 = _add_reduct_node(reduct.dependency)<EOL>id3 = scope_nodes[reduct.conflicting_request.name]<EOL>_add_reduct_edge(id1, id2, reduct.reducee_str())<EOL>_add_conflict_edge(id2, id3)<EOL>failure_nodes.add(id1)<EOL>failure_nodes.add(id2)<EOL>failure_nodes.add(id3)<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(fr, Cycle):<EOL><INDENT>for i, pkg in enumerate(fr.packages):<EOL><INDENT>id1 = scope_nodes[pkg.name]<EOL>failure_nodes.add(id1)<EOL>pkg2 = fr.packages[(i + <NUM_LIT:1>) % len(fr.packages)]<EOL>id2 = scope_nodes[pkg2.name]<EOL>_add_cycle_edge(id1, id2)<EOL><DEDENT><DEDENT><DEDENT>for request, id1 in request_nodes.items():<EOL><INDENT>if not g.neighbors(id1):  <EOL><INDENT>id2 = scope_nodes.get(request.name)<EOL>if id2 is not None:<EOL><INDENT>scope = scopes.get(request.name)<EOL>if not request.conflicts_with(scope.package_request):<EOL><INDENT>_add_edge(id1, id2)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if self.solver.prune_unfailed and failure_nodes:<EOL><INDENT>access_dict = accessibility(g)<EOL>del_nodes = set()<EOL>for n, access_nodes in access_dict.items():<EOL><INDENT>if not (set(access_nodes) & failure_nodes):<EOL><INDENT>del_nodes.add(n)<EOL><DEDENT><DEDENT>for n in del_nodes:<EOL><INDENT>g.del_node(n)<EOL><DEDENT><DEDENT>return g<EOL>
Get the resolve graph.

        The resolve graph shows what packages were resolved, and the
        relationships between them. A failed phase also has a graph, which
        will shows the conflict(s) that caused the resolve to fail.

        Returns:
            A pygraph.digraph object.