Bugfixes for yaml specs.

This commit is contained in:
Todd Gamblin 2015-05-05 14:24:46 -07:00
parent d687962b74
commit 1d0975bac6
3 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,5 @@
############################################################################## ##############################################################################
# Copyright (c) 2013, Lawrence Livermore National Security, LLC. # Copyright (c) 2013-2015, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory. # Produced at the Lawrence Livermore National Laboratory.
# #
# This file is part of Spack. # This file is part of Spack.
@ -96,6 +96,7 @@
from StringIO import StringIO from StringIO import StringIO
from operator import attrgetter from operator import attrgetter
from external import yaml from external import yaml
from external.yaml.error import MarkedYAMLError
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.lang import * from llnl.util.lang import *
@ -656,7 +657,11 @@ def from_yaml(string):
deps = {} deps = {}
spec = None spec = None
yfile = yaml.load(string) try:
yfile = yaml.load(string)
except MarkedYAMLError, e:
raise SpackYAMLError("error parsing YMAL spec:", str(e))
for node in yfile['spec']: for node in yfile['spec']:
name = next(iter(node)) name = next(iter(node))
dep = Spec.from_node_dict(node) dep = Spec.from_node_dict(node)
@ -1776,3 +1781,7 @@ class UnsatisfiableDependencySpecError(UnsatisfiableSpecError):
def __init__(self, provided, required): def __init__(self, provided, required):
super(UnsatisfiableDependencySpecError, self).__init__( super(UnsatisfiableDependencySpecError, self).__init__(
provided, required, "dependency") provided, required, "dependency")
class SpackYAMLError(spack.error.SpackError):
def __init__(self, msg, yaml_error):
super(SpackError, self).__init__(msg, str(yaml_error))

View File

@ -49,6 +49,12 @@ def test_normal_spec(self):
self.check_yaml_round_trip(spec) self.check_yaml_round_trip(spec)
def test_ambiguous_version_spec(self):
spec = Spec('mpileaks@1.0:5.0,6.1,7.3+debug~opt')
spec.normalize()
self.check_yaml_round_trip(spec)
def test_concrete_spec(self): def test_concrete_spec(self):
spec = Spec('mpileaks+debug~opt') spec = Spec('mpileaks+debug~opt')
spec.concretize() spec.concretize()

View File

@ -592,7 +592,7 @@ def to_dict(self):
if self.concrete: if self.concrete:
return { 'version' : str(self[0]) } return { 'version' : str(self[0]) }
else: else:
return { 'versions' : str(v) for v in self } return { 'versions' : [str(v) for v in self] }
@staticmethod @staticmethod