def prune_graph(graph_str, package_name): """Prune a package graph so it only contains nodes accessible from the given package. Args: graph_str (str): Dot-language graph string. package_name (str): Name of package of interest. Returns: Pruned graph, as a string. """ # find nodes of interest g = read_dot(graph_str) nodes = set() for node, attrs in g.node_attr.iteritems(): attr = [x for x in attrs if x[0] == "label"] if attr: label = attr[0][1] try: req_str = _request_from_label(label) request = PackageRequest(req_str) except PackageRequestError: continue if request.name == package_name: nodes.add(node) if not nodes: raise ValueError("The package %r does not appear in the graph." % package_name) # find nodes upstream from these nodes g_rev = g.reverse() accessible_nodes = set() access = accessibility(g_rev) for node in nodes: nodes_ = access.get(node, []) accessible_nodes |= set(nodes_) # remove inaccessible nodes inaccessible_nodes = set(g.nodes()) - accessible_nodes for node in inaccessible_nodes: g.del_node(node) return write_dot(g)
def command(opts, parser, extra_arg_groups=None): from rez.package_search import get_reverse_dependency_tree from rez.utils.graph_utils import save_graph, view_graph from rez.config import config from rez.vendor.pygraph.readwrite.dot import write as write_dot import os import os.path config.override("warn_none", True) config.override("show_progress", (not opts.quiet)) if opts.paths is None: pkg_paths = None else: pkg_paths = opts.paths.split(os.pathsep) pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x] pkgs_list, g = get_reverse_dependency_tree( package_name=opts.PKG, depth=opts.depth, paths=pkg_paths, build_requires=opts.build_requires, private_build_requires=opts.private_build_requires) if opts.graph or opts.print_graph or opts.write_graph: gstr = write_dot(g) if opts.print_graph: print(gstr) elif opts.write_graph: save_graph(gstr, dest_file=opts.write_graph) else: view_graph(gstr) return 0 for i, pkgs in enumerate(pkgs_list): if opts.quiet: toks = pkgs else: toks = ["#%d:" % i] + pkgs print(' '.join(toks))
def command(opts, parser, extra_arg_groups=None): from rez.package_search import get_reverse_dependency_tree from rez.utils.graph_utils import save_graph, view_graph from rez.config import config from rez.vendor.pygraph.readwrite.dot import write as write_dot import os import os.path config.override("warn_none", True) config.override("show_progress", (not opts.quiet)) if opts.paths is None: pkg_paths = None else: pkg_paths = opts.paths.split(os.pathsep) pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x] pkgs_list, g = get_reverse_dependency_tree( package_name=opts.PKG, depth=opts.depth, paths=pkg_paths, build_requires=opts.build_requires, private_build_requires=opts.private_build_requires) if opts.graph or opts.print_graph or opts.write_graph: gstr = write_dot(g) if opts.print_graph: print gstr elif opts.write_graph: save_graph(gstr, dest_file=opts.write_graph) else: view_graph(gstr) return 0 for i, pkgs in enumerate(pkgs_list): if opts.quiet: toks = pkgs else: toks = ["#%d:" % i] + pkgs print ' '.join(toks)
def _view_dependency_graph(self): from rez.vendor.pygraph.readwrite.dot import write as write_dot graph = self.context().get_dependency_graph() graph_str = write_dot(graph) view_graph(graph_str, self.window(), prune_to=self.package_name)