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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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

View File

@ -1885,7 +1885,7 @@ complete -c spack -n '__fish_spack_using_command graph' -s s -l static -d 'graph
complete -c spack -n '__fish_spack_using_command graph' -s c -l color -f -a color
complete -c spack -n '__fish_spack_using_command graph' -s c -l color -d 'use different colors for different dependency types'
complete -c spack -n '__fish_spack_using_command graph' -s i -l installed -f -a installed
complete -c spack -n '__fish_spack_using_command graph' -s i -l installed -d 'graph installed specs, or specs in the active env (implies --dot)'
complete -c spack -n '__fish_spack_using_command graph' -s i -l installed -d 'graph specs from the DB'
complete -c spack -n '__fish_spack_using_command graph' -l deptype -r -f -a deptype
complete -c spack -n '__fish_spack_using_command graph' -l deptype -r -d 'comma-separated list of deptypes to traverse (default=build,link,run,test)'