Add --all argument to spack dependents
--all causes spack dependents to list all possible dependents for a package, rather than actual dependents for an installed spec.
This commit is contained in:
parent
44653fa488
commit
f2ddcfac5f
1 changed files with 56 additions and 6 deletions
|
@ -25,6 +25,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
|
from llnl.util.tty.colify import colify
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
import spack.store
|
import spack.store
|
||||||
|
@ -36,20 +37,69 @@
|
||||||
|
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
|
subparser.add_argument(
|
||||||
|
'-a', '--all', action='store_true', default=False,
|
||||||
|
help="List all potential dependents of the package instead of actual "
|
||||||
|
"dependents of an installed spec")
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'spec', nargs=argparse.REMAINDER,
|
'spec', nargs=argparse.REMAINDER,
|
||||||
help="specs to list dependencies of")
|
help="specs to list dependencies of")
|
||||||
|
|
||||||
|
|
||||||
|
def inverted_dag():
|
||||||
|
"""Returns inverted package DAG as adjacency lists."""
|
||||||
|
dag = {}
|
||||||
|
for pkg in spack.repo.all_packages():
|
||||||
|
dag.setdefault(pkg.name, set())
|
||||||
|
for dep in pkg.dependencies:
|
||||||
|
deps = [dep]
|
||||||
|
|
||||||
|
# expand virtuals if necessary
|
||||||
|
if spack.repo.is_virtual(dep):
|
||||||
|
deps = [s.name for s in spack.repo.providers_for(dep)]
|
||||||
|
|
||||||
|
for d in deps:
|
||||||
|
dag.setdefault(d, set()).add(pkg.name)
|
||||||
|
return dag
|
||||||
|
|
||||||
|
|
||||||
|
def all_dependents(name, inverted_dag, dependents=None):
|
||||||
|
if dependents is None:
|
||||||
|
dependents = set()
|
||||||
|
|
||||||
|
if name in dependents:
|
||||||
|
return set()
|
||||||
|
dependents.add(name)
|
||||||
|
|
||||||
|
direct = inverted_dag[name]
|
||||||
|
for dname in direct:
|
||||||
|
all_dependents(dname, inverted_dag, dependents)
|
||||||
|
dependents.update(direct)
|
||||||
|
return dependents
|
||||||
|
|
||||||
|
|
||||||
def dependents(parser, args):
|
def dependents(parser, args):
|
||||||
specs = spack.cmd.parse_specs(args.spec)
|
specs = spack.cmd.parse_specs(args.spec)
|
||||||
if len(specs) != 1:
|
if len(specs) != 1:
|
||||||
tty.die("spack dependents takes only one spec.")
|
tty.die("spack dependents takes only one spec.")
|
||||||
spec = spack.cmd.disambiguate_spec(specs[0])
|
|
||||||
|
|
||||||
tty.msg("Dependents of %s" % spec.cformat('$_$@$%@$/'))
|
if args.all:
|
||||||
deps = spack.store.db.installed_dependents(spec)
|
spec = specs[0]
|
||||||
if deps:
|
idag = inverted_dag()
|
||||||
spack.cmd.display_specs(deps)
|
|
||||||
|
dependents = all_dependents(spec.name, idag)
|
||||||
|
dependents.remove(spec.name)
|
||||||
|
if dependents:
|
||||||
|
colify(sorted(dependents))
|
||||||
|
else:
|
||||||
|
print("No dependents")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("No dependents")
|
spec = spack.cmd.disambiguate_spec(specs[0])
|
||||||
|
|
||||||
|
tty.msg("Dependents of %s" % spec.cformat('$_$@$%@$/'))
|
||||||
|
deps = spack.store.db.installed_dependents(spec)
|
||||||
|
if deps:
|
||||||
|
spack.cmd.display_specs(deps)
|
||||||
|
else:
|
||||||
|
print("No dependents")
|
||||||
|
|
Loading…
Reference in a new issue