spec: simplify __str__ implementation (#23593)
The implementation for __str__ has been simplified to traverse the spec directly, and doesn't call anymore the flat_dependencies method. Dead code has been removed.
This commit is contained in:
parent
b70bf073b5
commit
f47066967b
2 changed files with 10 additions and 13 deletions
|
@ -3566,11 +3566,6 @@ def __contains__(self, spec):
|
||||||
else:
|
else:
|
||||||
return any(s.satisfies(spec) for s in self.traverse(root=False))
|
return any(s.satisfies(spec) for s in self.traverse(root=False))
|
||||||
|
|
||||||
def sorted_deps(self):
|
|
||||||
"""Return a list of all dependencies sorted by name."""
|
|
||||||
deps = self.flat_dependencies()
|
|
||||||
return tuple(deps[name] for name in sorted(deps))
|
|
||||||
|
|
||||||
def eq_dag(self, other, deptypes=True, vs=None, vo=None):
|
def eq_dag(self, other, deptypes=True, vs=None, vo=None):
|
||||||
"""True if the full dependency DAGs of specs are equal."""
|
"""True if the full dependency DAGs of specs are equal."""
|
||||||
if vs is None:
|
if vs is None:
|
||||||
|
@ -3880,7 +3875,9 @@ def write_attribute(spec, attribute, color):
|
||||||
'Format string terminated while reading attribute.'
|
'Format string terminated while reading attribute.'
|
||||||
'Missing terminating }.'
|
'Missing terminating }.'
|
||||||
)
|
)
|
||||||
return out.getvalue()
|
|
||||||
|
formatted_spec = out.getvalue()
|
||||||
|
return formatted_spec.strip()
|
||||||
|
|
||||||
def old_format(self, format_string='$_$@$%@+$+$=', **kwargs):
|
def old_format(self, format_string='$_$@$%@+$+$=', **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -4136,12 +4133,12 @@ def cformat(self, *args, **kwargs):
|
||||||
kwargs.setdefault('color', None)
|
kwargs.setdefault('color', None)
|
||||||
return self.format(*args, **kwargs)
|
return self.format(*args, **kwargs)
|
||||||
|
|
||||||
def dep_string(self):
|
|
||||||
return ''.join(" ^" + dep.format() for dep in self.sorted_deps())
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
ret = self.format() + self.dep_string()
|
sorted_nodes = [self] + sorted(
|
||||||
return ret.strip()
|
self.traverse(root=False), key=lambda x: x.name
|
||||||
|
)
|
||||||
|
spec_str = " ^".join(d.format() for d in sorted_nodes)
|
||||||
|
return spec_str.strip()
|
||||||
|
|
||||||
def install_status(self):
|
def install_status(self):
|
||||||
"""Helper for tree to print DB install status."""
|
"""Helper for tree to print DB install status."""
|
||||||
|
|
|
@ -776,7 +776,7 @@ def test_spec_formatting(self):
|
||||||
sigil_package_segments = [("{@VERSIONS}", '@' + str(spec.version)),
|
sigil_package_segments = [("{@VERSIONS}", '@' + str(spec.version)),
|
||||||
("{%compiler}", '%' + str(spec.compiler)),
|
("{%compiler}", '%' + str(spec.compiler)),
|
||||||
("{arch=architecture}",
|
("{arch=architecture}",
|
||||||
' arch=' + str(spec.architecture))]
|
'arch=' + str(spec.architecture))]
|
||||||
|
|
||||||
compiler_segments = [("{compiler.name}", "name"),
|
compiler_segments = [("{compiler.name}", "name"),
|
||||||
("{compiler.version}", "versions")]
|
("{compiler.version}", "versions")]
|
||||||
|
@ -798,7 +798,7 @@ def test_spec_formatting(self):
|
||||||
for named_str, prop in package_segments:
|
for named_str, prop in package_segments:
|
||||||
expected = getattr(spec, prop, "")
|
expected = getattr(spec, prop, "")
|
||||||
actual = spec.format(named_str)
|
actual = spec.format(named_str)
|
||||||
assert str(expected) == actual
|
assert str(expected).strip() == actual
|
||||||
|
|
||||||
for named_str, expected in sigil_package_segments:
|
for named_str, expected in sigil_package_segments:
|
||||||
actual = spec.format(named_str)
|
actual = spec.format(named_str)
|
||||||
|
|
Loading…
Reference in a new issue