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
This commit is contained in:
parent
6309c5eff5
commit
7c9c486d07
@ -17,6 +17,26 @@
|
|||||||
default_deptype = ('build', 'link')
|
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):
|
def canonical_deptype(deptype):
|
||||||
"""Convert deptype to a canonical sorted tuple, or raise ValueError.
|
"""Convert deptype to a canonical sorted tuple, or raise ValueError.
|
||||||
|
|
||||||
@ -108,3 +128,8 @@ def merge(self, other):
|
|||||||
self.patches[cond].extend(other.patches[cond])
|
self.patches[cond].extend(other.patches[cond])
|
||||||
else:
|
else:
|
||||||
self.patches[cond] = other.patches[cond]
|
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)
|
||||||
|
@ -3877,22 +3877,18 @@ def tree(self, **kwargs):
|
|||||||
'@K{%s} ', color=color) % node.dag_hash(hlen)
|
'@K{%s} ', color=color) % node.dag_hash(hlen)
|
||||||
|
|
||||||
if show_types:
|
if show_types:
|
||||||
types = set()
|
|
||||||
if cover == 'nodes':
|
if cover == 'nodes':
|
||||||
# when only covering nodes, we merge dependency types
|
# when only covering nodes, we merge dependency types
|
||||||
# from all dependents before showing them.
|
# from all dependents before showing them.
|
||||||
for name, ds in node.dependents_dict().items():
|
types = [
|
||||||
if ds.deptypes:
|
ds.deptypes for ds in node.dependents_dict().values()]
|
||||||
types.update(set(ds.deptypes))
|
else:
|
||||||
elif dep_spec.deptypes:
|
|
||||||
# when covering edges or paths, we show dependency
|
# when covering edges or paths, we show dependency
|
||||||
# types only for the edge through which we visited
|
# types only for the edge through which we visited
|
||||||
types = set(dep_spec.deptypes)
|
types = [dep_spec.deptypes]
|
||||||
|
|
||||||
out += '['
|
type_chars = dp.deptype_chars(*types)
|
||||||
for t in dp.all_deptypes:
|
out += '[%s] ' % type_chars
|
||||||
out += ''.join(t[0] if t in types else ' ')
|
|
||||||
out += '] '
|
|
||||||
|
|
||||||
out += (" " * d)
|
out += (" " * d)
|
||||||
if d > 0:
|
if d > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user