<commit_before>from spyc.graph import Vertex, find_cycle, topological_sort


class Scheduler(object):

    def __init__(self):
        self.specs = {}

    def ensure(self, spec):
        """Require that ``spec`` is satisfied."""
        if spec.key() in self.specs:
            self.specs[spec.key()].data.merge(spec)
        else:
            self.specs[spec.key()] = Vertex(spec)

    def depend(self, first, next):
        """Specify that ``first`` depends on ``next``.

        This also has the effect of invoking ``ensure`` on both resources.
        """
        first.schedule(self)
        next.schedule(self)
        self.specs[first.key()].edges.add(self.specs[next.key()])

    def apply(self):
        verticies = set(self.specs.values())
        cycle = find_cycle(verticies)
        if cycle is not None:
            assert False  # TODO proper checking<commit_msg>Raise a more useful error for circular deps.<commit_after>from spyc.graph import Vertex, find_cycle, topological_sort


class CircularDependency(Exception):
    pass


class Scheduler(object):

    def __init__(self):
        self.specs = {}

    def ensure(self, spec):
        """Require that ``spec`` is satisfied."""
        if spec.key() in self.specs:
            self.specs[spec.key()].data.merge(spec)
        else:
            self.specs[spec.key()] = Vertex(spec)

    def depend(self, first, next):
        """Specify that ``first`` depends on ``next``.

        This also has the effect of invoking ``ensure`` on both resources.
        """
        first.schedule(self)
        next.schedule(self)
        self.specs[first.key()].edges.add(self.specs[next.key()])

    def apply(self):
        verticies = set(self.specs.values())
        cycle = find_cycle(verticies)
        if cycle is not None:
            raise CircularDependency(cycle)
{'fraction_non_alphanumeric': 0.13140676117775354, 'fraction_numerical': 0.0, 'mean_word_length': 2.4427767354596623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6371565', 'n_tokens_mistral': 551, 'n_tokens_neox': 539, 'n_words': 140}