MCPcopy Index your code
hub / github.com/huggingface/diffusers / create_reverse_dependency_map

Function create_reverse_dependency_map

utils/tests_fetcher.py:729–778  ·  view source on GitHub ↗

Create the dependency map from module/test filename to the list of modules/tests that depend on it recursively. Returns: `Dict[str, List[str]]`: The reverse dependency map as a dictionary mapping filenames to all the filenames depending on it recursively. This way the tests

()

Source from the content-addressed store, hash-verified

727
728
729def create_reverse_dependency_map() -> dict[str, List[str]]:
730 """
731 Create the dependency map from module/test filename to the list of modules/tests that depend on it recursively.
732
733 Returns:
734 `Dict[str, List[str]]`: The reverse dependency map as a dictionary mapping filenames to all the filenames
735 depending on it recursively. This way the tests impacted by a change in file A are the test files in the list
736 corresponding to key A in this result.
737 """
738 cache = {}
739 # Start from the example deps init.
740 example_deps, examples = init_test_examples_dependencies()
741 # Add all modules and all tests to all examples
742 all_modules = list(PATH_TO_DIFFUSERS.glob("**/*.py")) + list(PATH_TO_TESTS.glob("**/*.py")) + examples
743 all_modules = [str(mod.relative_to(PATH_TO_REPO)) for mod in all_modules]
744 # Compute the direct dependencies of all modules.
745 direct_deps = {m: get_module_dependencies(m, cache=cache) for m in all_modules}
746 direct_deps.update(example_deps)
747
748 # This recurses the dependencies
749 something_changed = True
750 while something_changed:
751 something_changed = False
752 for m in all_modules:
753 for d in direct_deps[m]:
754 # We stop recursing at an init (cause we always end up in the main init and we don't want to add all
755 # files which the main init imports)
756 if d.endswith("__init__.py"):
757 continue
758 if d not in direct_deps:
759 raise ValueError(f"KeyError:{d}. From {m}")
760 new_deps = set(direct_deps[d]) - set(direct_deps[m])
761 if len(new_deps) > 0:
762 direct_deps[m].extend(list(new_deps))
763 something_changed = True
764
765 # Finally we can build the reverse map.
766 reverse_map = collections.defaultdict(list)
767 for m in all_modules:
768 for d in direct_deps[m]:
769 reverse_map[d].append(m)
770
771 # For inits, we don't do the reverse deps but the direct deps: if modifying an init, we want to make sure we test
772 # all the modules impacted by that init.
773 for m in [f for f in all_modules if f.endswith("__init__.py")]:
774 direct_deps = get_module_dependencies(m, cache=cache)
775 deps = sum([reverse_map[d] for d in direct_deps if not d.endswith("__init__.py")], direct_deps)
776 reverse_map[m] = list(set(deps) - {m})
777
778 return reverse_map
779
780
781def create_module_to_test_map(reverse_map: Dict[str, List[str]] = None) -> dict[str, List[str]]:

Callers 2

infer_tests_to_runFunction · 0.85

Calls 3

get_module_dependenciesFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…