diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2016-10-12 18:25:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-12 18:25:18 -0700 |
commit | d861a52ebec2a73451fde5870b92b2ff4fb81620 (patch) | |
tree | 0031c36bb4a4e7a7bd8ddda570cf8884ce4a07ac /lib | |
parent | b27f4e3aebf6c1ecbefffc22a9a27a4fe9ce0ab3 (diff) | |
download | spack-d861a52ebec2a73451fde5870b92b2ff4fb81620.tar.gz spack-d861a52ebec2a73451fde5870b92b2ff4fb81620.tar.bz2 spack-d861a52ebec2a73451fde5870b92b2ff4fb81620.tar.xz spack-d861a52ebec2a73451fde5870b92b2ff4fb81620.zip |
Use cYAML if it is available in Python. (#2010)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/spec.py | 7 | ||||
-rw-r--r-- | lib/spack/spack/util/spack_yaml.py | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index fc4bf41e34..37a3cf4d7e 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -98,7 +98,7 @@ expansion when it is the first character in an id typed on the command line. import base64 import hashlib import imp -import sys +import ctypes from StringIO import StringIO from operator import attrgetter @@ -203,6 +203,9 @@ special_types = { legal_deps = tuple(special_types) + alldeps +"""Max integer helps avoid passing too large a value to cyaml.""" +maxint = 2 ** (ctypes.sizeof(ctypes.c_int) * 8 - 1) - 1 + def validate_deptype(deptype): if isinstance(deptype, str): @@ -969,7 +972,7 @@ class Spec(object): return self._hash[:length] else: yaml_text = syaml.dump( - self.to_node_dict(), default_flow_style=True, width=sys.maxint) + self.to_node_dict(), default_flow_style=True, width=maxint) sha = hashlib.sha1(yaml_text) b32_hash = base64.b32encode(sha.digest()).lower()[:length] if self.concrete: diff --git a/lib/spack/spack/util/spack_yaml.py b/lib/spack/spack/util/spack_yaml.py index 7bcdf2d61f..506f56633a 100644 --- a/lib/spack/spack/util/spack_yaml.py +++ b/lib/spack/spack/util/spack_yaml.py @@ -32,6 +32,10 @@ """ import yaml +try: + from yaml import CLoader as Loader, CDumper as Dumper +except ImportError as e: + from yaml import Loader, Dumper from yaml.nodes import * from yaml.constructor import ConstructorError from ordereddict_backport import OrderedDict @@ -64,7 +68,7 @@ def mark(obj, node): obj._end_mark = node.end_mark -class OrderedLineLoader(yaml.Loader): +class OrderedLineLoader(Loader): """YAML loader that preserves order and line numbers. Mappings read in by this loader behave like an ordered dict. @@ -156,7 +160,7 @@ OrderedLineLoader.add_constructor( u'tag:yaml.org,2002:str', OrderedLineLoader.construct_yaml_str) -class OrderedLineDumper(yaml.Dumper): +class OrderedLineDumper(Dumper): """Dumper that preserves ordering and formats ``syaml_*`` objects. This dumper preserves insertion ordering ``syaml_dict`` objects |