def toposort(tasks):
    """Simple topological sort routine for task lists. Not fast, but easy
    - especially leaves nodes in original order if already topologically
    sorted. Dependencies that are not in the tasks list are ignored for
    the purpose of the sort.
    """

    tasks_set = set(tasks)
    tasks_out = []
    tasks_out_set = set()
    to_do = tasks
    while len(to_do) > 0:
        new_to_do = []
        for t in to_do:
            if set(t.deps).intersection(tasks_set).issubset(tasks_out_set):
                tasks_out.append(t)
                tasks_out_set.add(t)
            else:
                new_to_do.append(t)
        to_do = new_to_do
    return tasks_out