def dependent_environments(specs): """Map each spec to environments that depend on it. Args: specs (list): list of Specs Returns: (dict): mapping from spec to lists of dependent Environments """ dependents = {} for env in ev.all_environments(): hashes = set(env.all_hashes()) for spec in specs: if spec.dag_hash() in hashes: dependents.setdefault(spec, []).append(env) return dependents