spack graph: env aware (#42093)

This commit is contained in:
Massimiliano Culpo
2024-01-18 10:11:41 +01:00
committed by GitHub
parent 7b27591321
commit 203d682d87
2 changed files with 23 additions and 15 deletions

View File

@@ -18,7 +18,14 @@
def setup_parser(subparser):
setup_parser.parser = subparser
subparser.epilog = """
Outside of an environment, the command concretizes specs and graphs them, unless the
--installed option is given. In that case specs are matched from the current DB.
If an environment is active, specs are matched from the currently available concrete specs
in the lockfile.
"""
method = subparser.add_mutually_exclusive_group()
method.add_argument(
"-a", "--ascii", action="store_true", help="draw graph as ascii to stdout (default)"
@@ -41,39 +48,40 @@ def setup_parser(subparser):
)
subparser.add_argument(
"-i",
"--installed",
action="store_true",
help="graph installed specs, or specs in the active env (implies --dot)",
"-i", "--installed", action="store_true", help="graph specs from the DB"
)
arguments.add_common_arguments(subparser, ["deptype", "specs"])
def graph(parser, args):
if args.installed and args.specs:
tty.die("cannot specify specs with --installed")
env = ev.active_environment()
if args.installed and env:
tty.die("cannot use --installed with an active environment")
if args.color and not args.dot:
tty.die("the --color option can be used only with --dot")
if args.installed:
args.dot = True
env = ev.active_environment()
if env:
specs = env.concrete_roots()
else:
if not args.specs:
specs = spack.store.STORE.db.query()
else:
result = []
for item in args.specs:
result.extend(spack.store.STORE.db.query(item))
specs = list(set(result))
elif env:
specs = env.concrete_roots()
if args.specs:
specs = env.all_matching_specs(*args.specs)
else:
specs = spack.cmd.parse_specs(args.specs, concretize=not args.static)
if not specs:
setup_parser.parser.print_help()
return 1
tty.die("no spec matching the query")
if args.static:
args.dot = True
static_graph_dot(specs, depflag=args.deptype)
return