Refactor installed_dependents -> installed_relatives
This commit is contained in:
parent
36b3dd8cfe
commit
c8b2100630
4 changed files with 34 additions and 15 deletions
|
@ -45,8 +45,7 @@ def setup_parser(subparser):
|
|||
'-t', '--transitive', action='store_true', default=False,
|
||||
help="Show all transitive dependents.")
|
||||
subparser.add_argument(
|
||||
'spec', nargs=argparse.REMAINDER,
|
||||
help="spec or package name")
|
||||
'spec', nargs=argparse.REMAINDER, help="spec or package name")
|
||||
|
||||
|
||||
def inverted_dependencies():
|
||||
|
@ -104,7 +103,8 @@ def dependents(parser, args):
|
|||
spec = spack.cmd.disambiguate_spec(specs[0])
|
||||
|
||||
tty.msg("Dependents of %s" % spec.cformat('$_$@$%@$/'))
|
||||
deps = spack.store.db.installed_dependents(spec)
|
||||
deps = spack.store.db.installed_relatives(
|
||||
spec, 'parents', args.transitive)
|
||||
if deps:
|
||||
spack.cmd.display_specs(deps)
|
||||
else:
|
||||
|
|
|
@ -128,8 +128,8 @@ def installed_dependents(specs):
|
|||
"""
|
||||
dependents = {}
|
||||
for item in specs:
|
||||
lst = [x for x in spack.store.db.installed_dependents(item)
|
||||
if x not in specs]
|
||||
installed = spack.store.db.installed_relatives(item, 'parents', True)
|
||||
lst = [x for x in installed if x not in specs]
|
||||
if lst:
|
||||
lst = list(set(lst))
|
||||
dependents[item] = lst
|
||||
|
@ -157,7 +157,9 @@ def do_uninstall(specs, force):
|
|||
# Sort packages to be uninstalled by the number of installed dependents
|
||||
# This ensures we do things in the right order
|
||||
def num_installed_deps(pkg):
|
||||
return len(spack.store.db.installed_dependents(pkg.spec))
|
||||
dependents = spack.store.db.installed_relatives(
|
||||
pkg.spec, 'parents', True)
|
||||
return len(dependents)
|
||||
|
||||
packages.sort(key=num_installed_deps)
|
||||
for item in packages:
|
||||
|
|
|
@ -711,18 +711,34 @@ def remove(self, spec):
|
|||
return self._remove(spec)
|
||||
|
||||
@_autospec
|
||||
def installed_dependents(self, spec, transitive=True):
|
||||
"""List the installed specs that depend on this one."""
|
||||
dependents = set()
|
||||
def installed_relatives(self, spec, direction='children', transitive=True):
|
||||
"""Return installed specs related to this one."""
|
||||
if direction not in ('parents', 'children'):
|
||||
raise ValueError("Invalid direction: %s" % direction)
|
||||
|
||||
relatives = set()
|
||||
for spec in self.query(spec):
|
||||
if transitive:
|
||||
to_add = spec.traverse(direction='parents', root=False)
|
||||
else:
|
||||
to_add = spec.traverse(direction=direction, root=False)
|
||||
elif direction == 'parents':
|
||||
to_add = spec.dependents()
|
||||
else: # direction == 'children'
|
||||
to_add = spec.dependencies()
|
||||
|
||||
for dependent in to_add:
|
||||
dependents.add(dependent)
|
||||
return dependents
|
||||
for relative in to_add:
|
||||
hash_key = relative.dag_hash()
|
||||
if hash_key not in self._data:
|
||||
reltype = ('Dependent' if direction == 'parents'
|
||||
else 'Dependency')
|
||||
tty.warn("Inconsistent state! %s %s of %s not in DB"
|
||||
% (reltype, hash_key, spec.dag_hash()))
|
||||
continue
|
||||
|
||||
if not self._data[hash_key].installed:
|
||||
continue
|
||||
|
||||
relatives.add(relative)
|
||||
return relatives
|
||||
|
||||
@_autospec
|
||||
def installed_extensions_for(self, extendee_spec):
|
||||
|
|
|
@ -1582,7 +1582,8 @@ def uninstall_by_spec(spec, force=False):
|
|||
raise InstallError(str(spec) + " is not installed.")
|
||||
|
||||
if not force:
|
||||
dependents = spack.store.db.installed_dependents(spec)
|
||||
dependents = spack.store.db.installed_relatives(
|
||||
spec, 'parents', True)
|
||||
if dependents:
|
||||
raise PackageStillNeededError(spec, dependents)
|
||||
|
||||
|
|
Loading…
Reference in a new issue