From fafe1cb7e81e6e6f0b3dc3e4c365f176cc7e1fb6 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 25 Aug 2021 07:41:04 -0700 Subject: Make `spack graph -i` environment-aware (#25599) This allows you to run `spack graph --installed` from within an environment and get a dot graph of its concrete specs. - [x] make `spack graph -i` environment-aware - [x] add code to the generated dot graph to ensure roots have min rank (i.e., they're all at the top or left of the DAG) --- lib/spack/spack/cmd/graph.py | 10 ++++++++-- lib/spack/spack/graph.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/cmd/graph.py b/lib/spack/spack/cmd/graph.py index c7675f1ada..0078149508 100644 --- a/lib/spack/spack/cmd/graph.py +++ b/lib/spack/spack/cmd/graph.py @@ -10,6 +10,7 @@ import llnl.util.tty as tty import spack.cmd import spack.cmd.common.arguments as arguments import spack.config +import spack.environment as ev import spack.store from spack.graph import graph_ascii, graph_dot @@ -35,7 +36,7 @@ def setup_parser(subparser): subparser.add_argument( '-i', '--installed', action='store_true', - help="graph all installed specs in dot format (implies --dot)") + help="graph installed specs, or specs in the active env (implies --dot)") arguments.add_common_arguments(subparser, ['deptype', 'specs']) @@ -45,7 +46,12 @@ def graph(parser, args): if args.specs: tty.die("Can't specify specs with --installed") args.dot = True - specs = spack.store.db.query() + + env = ev.active_environment() + if env: + specs = env.all_specs() + else: + specs = spack.store.db.query() else: specs = spack.cmd.parse_specs(args.specs, concretize=not args.static) diff --git a/lib/spack/spack/graph.py b/lib/spack/spack/graph.py index 7ca7b11af7..84acfd37ef 100644 --- a/lib/spack/spack/graph.py +++ b/lib/spack/spack/graph.py @@ -550,11 +550,21 @@ def graph_dot(specs, deptype='all', static=False, out=None): out.write(' style="rounded,filled"') out.write(' ]\n') + # write nodes out.write('\n') for key, label in nodes: out.write(' "%s" [label="%s"]\n' % (key, label)) + # write edges out.write('\n') for src, dest in edges: out.write(' "%s" -> "%s"\n' % (src, dest)) + + # ensure that roots are all at the top of the plot + dests = set([d for _, d in edges]) + roots = ['"%s"' % k for k, _ in nodes if k not in dests] + out.write('\n') + out.write(' { rank=min; %s; }' % "; ".join(roots)) + + out.write('\n') out.write('}\n') -- cgit v1.2.3-60-g2f50