def _get_dependency_order(g, node_list):
access_ = accessibility(g)<EOL>deps = dict((k, set(v) - set([k])) for k, v in access_.items())<EOL>nodes = node_list + list(set(g.nodes()) - set(node_list))<EOL>ordered_nodes = []<EOL>while nodes:<EOL><INDENT>n_ = nodes[<NUM_LIT:0>]<EOL>n_deps = deps.get(n_)<EOL>if (n_ in ordered_nodes) or (n_deps is None):<EOL><INDENT>nodes = nodes[<NUM_LIT:1>:]<EOL>continue<EOL><DEDENT>moved = False<EOL>for i, n in enumerate(nodes[<NUM_LIT:1>:]):<EOL><INDENT>if n in n_deps:<EOL><INDENT>nodes = [nodes[i + <NUM_LIT:1>]] + nodes[:i + <NUM_LIT:1>] + nodes[i + <NUM_LIT:2>:]<EOL>moved = True<EOL>break<EOL><DEDENT><DEDENT>if not moved:<EOL><INDENT>ordered_nodes.append(n_)<EOL>nodes = nodes[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>return ordered_nodes<EOL>
Return list of nodes as close as possible to the ordering in node_list,
    but with child nodes earlier in the list than parents.