diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2017-06-17 18:14:44 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2017-08-01 17:40:54 -0700 |
commit | b9606e3157652b6fd65868afd44f6fc1fb02d204 (patch) | |
tree | 2465c9741e60589336804660f158f4dc9fdb006d | |
parent | 6928cf7a68c72d01472a766669790b12425092ad (diff) | |
download | spack-b9606e3157652b6fd65868afd44f6fc1fb02d204.tar.gz spack-b9606e3157652b6fd65868afd44f6fc1fb02d204.tar.bz2 spack-b9606e3157652b6fd65868afd44f6fc1fb02d204.tar.xz spack-b9606e3157652b6fd65868afd44f6fc1fb02d204.zip |
Add --transitive option to `spack dependents`
-rw-r--r-- | lib/spack/spack/cmd/dependents.py | 17 | ||||
-rw-r--r-- | lib/spack/spack/database.py | 9 |
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/spack/spack/cmd/dependents.py b/lib/spack/spack/cmd/dependents.py index 0d470e7a89..166f9e129c 100644 --- a/lib/spack/spack/cmd/dependents.py +++ b/lib/spack/spack/cmd/dependents.py @@ -31,7 +31,7 @@ import spack import spack.store import spack.cmd -description = "show installed packages that depend on another" +description = "show packages that depend on another" section = "basic" level = "long" @@ -42,8 +42,11 @@ def setup_parser(subparser): help="List installed dependents of an installed spec, " "instead of possible dependents of a package.") subparser.add_argument( + '-t', '--transitive', action='store_true', default=False, + help="Show all transitive dependents.") + subparser.add_argument( 'spec', nargs=argparse.REMAINDER, - help="spec to list dependents for") + help="spec or package name") def inverted_dependencies(): @@ -69,12 +72,13 @@ def inverted_dependencies(): return dag -def get_dependents(pkg_name, ideps, dependents=None): +def get_dependents(pkg_name, ideps, transitive=False, dependents=None): """Get all dependents for a package. Args: pkg_name (str): name of the package whose dependents should be returned ideps (dict): dictionary of dependents, from inverted_dependencies() + transitive (bool, optional): return transitive dependents when True """ if dependents is None: dependents = set() @@ -84,8 +88,9 @@ def get_dependents(pkg_name, ideps, dependents=None): dependents.add(pkg_name) direct = ideps[pkg_name] - for dep_name in direct: - get_dependents(dep_name, ideps, dependents) + if transitive: + for dep_name in direct: + get_dependents(dep_name, ideps, transitive, dependents) dependents.update(direct) return dependents @@ -109,7 +114,7 @@ def dependents(parser, args): spec = specs[0] ideps = inverted_dependencies() - dependents = get_dependents(spec.name, ideps) + dependents = get_dependents(spec.name, ideps, args.transitive) dependents.remove(spec.name) if dependents: colify(sorted(dependents)) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index 569de40a94..862eb25e7e 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -711,11 +711,16 @@ class Database(object): return self._remove(spec) @_autospec - def installed_dependents(self, spec): + def installed_dependents(self, spec, transitive=True): """List the installed specs that depend on this one.""" dependents = set() for spec in self.query(spec): - for dependent in spec.traverse(direction='parents', root=False): + if transitive: + to_add = spec.traverse(direction='parents', root=False) + else: + to_add = spec.dependents() + + for dependent in to_add: dependents.add(dependent) return dependents |