Fix bugs with sparse spec printing.

- Make namespace, arch, and dependnecies show up in spec yaml
  only if they're set.

- Lost some of this functionality with deptypes
This commit is contained in:
Todd Gamblin 2016-08-07 18:36:11 -07:00
parent 1339714eec
commit 2042e9a6d8
3 changed files with 34 additions and 10 deletions

View File

@ -383,6 +383,13 @@ def __str__(self):
def __contains__(self, string):
return string in str(self)
# TODO: make this unnecessary: don't include an empty arch on *every* spec.
def __nonzero__(self):
return (self.platform is not None or
self.platform_os is not None or
self.target is not None)
__bool__ = __nonzero__
def _cmp_key(self):
if isinstance(self.platform, Platform):
platform = self.platform.name

View File

@ -915,10 +915,7 @@ def to_node_dict(self):
if params:
d['parameters'] = params
if self.architecture is not None:
d['arch'] = self.architecture
if self.dependencies:
if self.dependencies():
deps = self.dependencies_dict(deptype=('link', 'run'))
d['dependencies'] = dict(
(name, {
@ -926,17 +923,13 @@ def to_node_dict(self):
'type': [str(s) for s in dspec.deptypes]})
for name, dspec in deps.items())
# Older concrete specs do not have a namespace. Omit for
# consistent hashing.
if not self.concrete or self.namespace:
if self.namespace:
d['namespace'] = self.namespace
if self.architecture:
# TODO: Fix the target.to_dict to account for the tuple
# Want it to be a dict of dicts
d['arch'] = self.architecture.to_dict()
else:
d['arch'] = None
if self.compiler:
d.update(self.compiler.to_dict())
@ -967,7 +960,8 @@ def from_node_dict(node):
if 'version' in node or 'versions' in node:
spec.versions = VersionList.from_dict(node)
spec.architecture = spack.architecture.arch_from_dict(node['arch'])
if 'arch' in node:
spec.architecture = spack.architecture.arch_from_dict(node['arch'])
if 'compiler' in node:
spec.compiler = CompilerSpec.from_dict(node)

View File

@ -86,6 +86,29 @@ def test_platform(self):
self.assertEqual(str(output_platform_class), str(my_platform_class))
def test_boolness(self):
# Make sure architecture reports that it's False when nothing's set.
arch = spack.architecture.Arch()
self.assertFalse(arch)
# Dummy architecture parts
plat = spack.architecture.platform()
plat_os = plat.operating_system('default_os')
plat_target = plat.target('default_target')
# Make sure architecture reports that it's True when anything is set.
arch = spack.architecture.Arch()
arch.platform = plat
self.assertTrue(arch)
arch = spack.architecture.Arch()
arch.platform_os = plat_os
self.assertTrue(arch)
arch = spack.architecture.Arch()
arch.target = plat_target
self.assertTrue(arch)
def test_user_front_end_input(self):
"""Test when user inputs just frontend that both the frontend target
and frontend operating system match