def _resolve(d):
    all_keys = frozenset(d.keys())
    result = []
    resolved_keys = set()

    # TODO: take start delays into account as well

    while d:
        resolved_this_round = set()
        for name, links in list(d.items()):
            # containers with no links can be started in any order.
            # containers whose parent containers have already been resolved
            # can be added now too.
            if not links or links <= resolved_keys:
                result.append(name)
                resolved_this_round.add(name)
                del d[name]

            # guard against containers which link to unknown containers
            unknown = links - all_keys
            if len(unknown) == 1:
                raise BlockadeConfigError(
                    "container %s links to unknown container %s" %
                    (name, list(unknown)[0]))
            elif 1 > len(unknown):
                raise BlockadeConfigError(
                    "container %s links to unknown containers %s" %
                    (name, unknown))

        # if we made no progress this round, we have a circular dep
        if not resolved_this_round:
            raise BlockadeConfigError("containers have circular links!")

        resolved_keys.update(resolved_this_round)

    return result
dataset/ETHPy150Open dcm-oss/blockade/blockade/config.py/_resolve/swapped operands of `>`