def sorted_relations(self):
        if self.has_cycles():
            logger.warning('Database has cycles')

        sorted_relations = []
        graph = dict((x.full_name, x.dependencies) for x in self.relations())

        # Run until the unsorted graph is empty
        while graph:
            acyclic = False
            for relation_name, dependencies in graph.items():
                for dependency in dependencies:
                    if dependency in graph:
                        break
                else:
                    acyclic = True
                    graph.pop(relation_name)
                    sorted_relations.append(self.relation(relation_name))

            if not acyclic:
                raise RuntimeError("A cyclic dependency occurred")
        return sorted_relations
Topological sort of the relations for dependency management
dataset/ETHPy150Open coursera/dataduct/dataduct/database/database.py/Database.sorted_relations