summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2020-08-09 15:33:31 -0700
committerGitHub <noreply@github.com>2020-08-09 15:33:31 -0700
commit7c9c486d075e0a8d3d1a8cf5d8f29fafaf7b79c8 (patch)
treef7abedfb9033dd24a126aa6984f6265dadd6f0a0 /lib
parent6309c5eff538af5a08012bbf7a9fac391717ae42 (diff)
downloadspack-7c9c486d075e0a8d3d1a8cf5d8f29fafaf7b79c8.tar.gz
spack-7c9c486d075e0a8d3d1a8cf5d8f29fafaf7b79c8.tar.bz2
spack-7c9c486d075e0a8d3d1a8cf5d8f29fafaf7b79c8.tar.xz
spack-7c9c486d075e0a8d3d1a8cf5d8f29fafaf7b79c8.zip
deptypes: move deptype formatting code from Spec.format to dependency.py (#17843)
- This simplifies Spec.format somewhat - Makes code to generate deptype strings (e.g., '[blrt]') reusable
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/dependency.py25
-rw-r--r--lib/spack/spack/spec.py16
2 files changed, 31 insertions, 10 deletions
diff --git a/lib/spack/spack/dependency.py b/lib/spack/spack/dependency.py
index e6b6c9cedc..fe7d6b5983 100644
--- a/lib/spack/spack/dependency.py
+++ b/lib/spack/spack/dependency.py
@@ -17,6 +17,26 @@ all_deptypes = ('build', 'link', 'run', 'test')
default_deptype = ('build', 'link')
+def deptype_chars(*type_tuples):
+ """Create a string representing deptypes for many dependencies.
+
+ The string will be some subset of 'blrt', like 'bl ', 'b t', or
+ ' lr ' where each letter in 'blrt' stands for 'build', 'link',
+ 'run', and 'test' (the dependency types).
+
+ For a single dependency, this just indicates that the dependency has
+ the indicated deptypes. For a list of dependnecies, this shows
+ whether ANY dpeendency in the list has the deptypes (so the deptypes
+ are merged).
+ """
+ types = set()
+ for t in type_tuples:
+ if t:
+ types.update(t)
+
+ return ''.join(t[0] if t in types else ' ' for t in all_deptypes)
+
+
def canonical_deptype(deptype):
"""Convert deptype to a canonical sorted tuple, or raise ValueError.
@@ -108,3 +128,8 @@ class Dependency(object):
self.patches[cond].extend(other.patches[cond])
else:
self.patches[cond] = other.patches[cond]
+
+ def __repr__(self):
+ types = deptype_chars(self.type)
+ return '<Dependency: %s -> %s [%s]>' % (
+ self.pkg.name, self.spec, types)
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 175d160855..227652168c 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -3877,22 +3877,18 @@ class Spec(object):
'@K{%s} ', color=color) % node.dag_hash(hlen)
if show_types:
- types = set()
if cover == 'nodes':
# when only covering nodes, we merge dependency types
# from all dependents before showing them.
- for name, ds in node.dependents_dict().items():
- if ds.deptypes:
- types.update(set(ds.deptypes))
- elif dep_spec.deptypes:
+ types = [
+ ds.deptypes for ds in node.dependents_dict().values()]
+ else:
# when covering edges or paths, we show dependency
# types only for the edge through which we visited
- types = set(dep_spec.deptypes)
+ types = [dep_spec.deptypes]
- out += '['
- for t in dp.all_deptypes:
- out += ''.join(t[0] if t in types else ' ')
- out += '] '
+ type_chars = dp.deptype_chars(*types)
+ out += '[%s] ' % type_chars
out += (" " * d)
if d > 0: