def prune_graph(graph_str, package_name):
<EOL>g = read_dot(graph_str)<EOL>nodes = set()<EOL>for node, attrs in g.node_attr.items():<EOL><INDENT>attr = [x for x in attrs if x[<NUM_LIT:0>] == "<STR_LIT:label>"]<EOL>if attr:<EOL><INDENT>label = attr[<NUM_LIT:0>][<NUM_LIT:1>]<EOL>try:<EOL><INDENT>req_str = _request_from_label(label)<EOL>request = PackageRequest(req_str)<EOL><DEDENT>except PackageRequestError:<EOL><INDENT>continue<EOL><DEDENT>if request.name == package_name:<EOL><INDENT>nodes.add(node)<EOL><DEDENT><DEDENT><DEDENT>if not nodes:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>% package_name)<EOL><DEDENT>g_rev = g.reverse()<EOL>accessible_nodes = set()<EOL>access = accessibility(g_rev)<EOL>for node in nodes:<EOL><INDENT>nodes_ = access.get(node, [])<EOL>accessible_nodes |= set(nodes_)<EOL><DEDENT>inaccessible_nodes = set(g.nodes()) - accessible_nodes<EOL>for node in inaccessible_nodes:<EOL><INDENT>g.del_node(node)<EOL><DEDENT>return write_dot(g)<EOL>
Prune a package graph so it only contains nodes accessible from the
    given package.

    Args:
        graph_str (str): Dot-language graph string.
        package_name (str): Name of package of interest.

    Returns:
        Pruned graph, as a string.