summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-06-17 19:20:05 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2017-08-01 17:40:54 -0700
commitc8b2100630698a214f5787a3c51f44debfa23252 (patch)
tree6d09041ec14e6cb0291986f4736f6a7ed8d1306b /lib
parent36b3dd8cfe1b932bd60f13606e9bfe23d8d91ffd (diff)
downloadspack-c8b2100630698a214f5787a3c51f44debfa23252.tar.gz
spack-c8b2100630698a214f5787a3c51f44debfa23252.tar.bz2
spack-c8b2100630698a214f5787a3c51f44debfa23252.tar.xz
spack-c8b2100630698a214f5787a3c51f44debfa23252.zip
Refactor installed_dependents -> installed_relatives
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/dependents.py6
-rw-r--r--lib/spack/spack/cmd/uninstall.py8
-rw-r--r--lib/spack/spack/database.py32
-rw-r--r--lib/spack/spack/package.py3
4 files changed, 34 insertions, 15 deletions
diff --git a/lib/spack/spack/cmd/dependents.py b/lib/spack/spack/cmd/dependents.py
index 166f9e129c..82a85e1180 100644
--- a/lib/spack/spack/cmd/dependents.py
+++ b/lib/spack/spack/cmd/dependents.py
@@ -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:
diff --git a/lib/spack/spack/cmd/uninstall.py b/lib/spack/spack/cmd/uninstall.py
index d4e88288d2..e95a5f3430 100644
--- a/lib/spack/spack/cmd/uninstall.py
+++ b/lib/spack/spack/cmd/uninstall.py
@@ -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:
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index 862eb25e7e..6b54dc5939 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -711,18 +711,34 @@ class Database(object):
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 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
- for dependent in to_add:
- dependents.add(dependent)
- return dependents
+ relatives.add(relative)
+ return relatives
@_autospec
def installed_extensions_for(self, extendee_spec):
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index ff8c629ee7..bdf56af608 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1582,7 +1582,8 @@ class PackageBase(with_metaclass(PackageMeta, object)):
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)