summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <gamblin2@llnl.gov>2021-08-25 07:41:04 -0700
committerGitHub <noreply@github.com>2021-08-25 07:41:04 -0700
commitfafe1cb7e81e6e6f0b3dc3e4c365f176cc7e1fb6 (patch)
treeac020e78a9ec30a57ba40c4e9e01d811385fec83
parent3e2f890467d448f746244be9d30b2f78aefe0dcb (diff)
downloadspack-fafe1cb7e81e6e6f0b3dc3e4c365f176cc7e1fb6.tar.gz
spack-fafe1cb7e81e6e6f0b3dc3e4c365f176cc7e1fb6.tar.bz2
spack-fafe1cb7e81e6e6f0b3dc3e4c365f176cc7e1fb6.tar.xz
spack-fafe1cb7e81e6e6f0b3dc3e4c365f176cc7e1fb6.zip
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)
-rw-r--r--lib/spack/spack/cmd/graph.py10
-rw-r--r--lib/spack/spack/graph.py10
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')