def siblings(client, revision, paths): """Show siblings for given paths.""" graph = Graph(client) nodes = graph.build(paths=paths, revision=revision) siblings_ = set(nodes) for node in nodes: siblings_ |= graph.siblings(node) paths = {node.path for node in siblings_} for path in paths: click.echo(graph._format_path(path))
def siblings(client, revision, flat, verbose, paths): """Show siblings for given paths.""" graph = Graph(client) nodes = graph.build(paths=paths, revision=revision) nodes = [n for n in nodes if not isinstance(n, Entity) or n.parent] sibling_sets = {frozenset([n]) for n in set(nodes)} for node in nodes: try: sibling_sets.add(frozenset(graph.siblings(node))) except (errors.InvalidOutputPath): # ignore nodes that aren't outputs if no path was supplied if paths: raise else: sibling_sets.discard({node}) result_sets = [] for candidate in sibling_sets: new_result = [] for result in result_sets: if candidate & result: candidate |= result else: new_result.append(result) result_sets = new_result result_sets.append(candidate) result = [[sibling_name(graph, node, verbose) for node in r] for r in result_sets] if flat: click.echo('\n'.join({n for r in result for n in r})) else: click.echo('\n---\n'.join('\n'.join(r) for r in result))