MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / get_tree_starting_at

Function get_tree_starting_at

diffusers/utils/tests_fetcher.py:632–657  ·  view source on GitHub ↗

Returns the tree starting at a given module following all edges. Args: module (`str`): The module that will be the root of the subtree we want. edges (`List[Tuple[str, str]]`): The list of all edges of the tree. Returns: `List[Union[str, List[str]]]`: The tree

(module: str, edges: List[Tuple[str, str]])

Source from the content-addressed store, hash-verified

630
631
632def get_tree_starting_at(module: str, edges: List[Tuple[str, str]]) -> List[Union[str, List[str]]]:
633 """
634 Returns the tree starting at a given module following all edges.
635
636 Args:
637 module (`str`): The module that will be the root of the subtree we want.
638 edges (`List[Tuple[str, str]]`): The list of all edges of the tree.
639
640 Returns:
641 `List[Union[str, List[str]]]`: The tree to print in the following format: [module, [list of edges
642 starting at module], [list of edges starting at the preceding level], ...]
643 """
644 vertices_seen = [module]
645 new_edges = [edge for edge in edges if edge[0] == module and edge[1] != module and "__init__.py" not in edge[1]]
646 tree = [module]
647 while len(new_edges) > 0:
648 tree.append(new_edges)
649 final_vertices = list({edge[1] for edge in new_edges})
650 vertices_seen.extend(final_vertices)
651 new_edges = [
652 edge
653 for edge in edges
654 if edge[0] in final_vertices and edge[1] not in vertices_seen and "__init__.py" not in edge[1]
655 ]
656
657 return tree
658
659
660def print_tree_deps_of(module, all_edges=None):

Callers 1

print_tree_deps_ofFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected