diff options
author | Jürg Billeter <j@bitron.ch> | 2017-07-04 08:54:41 +0200 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-05 20:32:20 +0900 |
commit | 3ba6b89bf3fdfcadf95565215a3d3380c112fcf2 (patch) | |
tree | 09184e38577f4dbc5b3d12e4e9422ac0071cfaf8 /buildstream/_yaml.py | |
parent | 39a3d1814740607d9323b92e9bc0f9d4a268c595 (diff) | |
download | buildstream-3ba6b89bf3fdfcadf95565215a3d3380c112fcf2.tar.gz |
_yaml.py: Dump sanitized mappings as unordered mappings
This eliminates the incorrect !!omap tags for unordered mappings.
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r-- | buildstream/_yaml.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index 537f4cacd..93fae4903 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -23,6 +23,7 @@ import copy from enum import Enum from ruamel import yaml +from ruamel.yaml.representer import SafeRepresenter, RoundTripRepresenter from . import ImplError, LoadError, LoadErrorReason @@ -538,6 +539,17 @@ def composite(target, source, policy=CompositePolicy.OVERWRITE, typesafe=False): e.actual_type.__name__)) from e +# SanitizedDict is an OrderedDict that is dumped as unordered mapping. +# This provides deterministic output for unordered mappings. +# +class SanitizedDict(collections.OrderedDict): + pass + + +RoundTripRepresenter.add_representer(SanitizedDict, + SafeRepresenter.represent_dict) + + # node_sanitize() # # Returnes an alphabetically ordered recursive copy @@ -549,7 +561,7 @@ def node_sanitize(node): if isinstance(node, collections.Mapping): - result = collections.OrderedDict() + result = SanitizedDict() for key in sorted(node): if key == PROVENANCE_KEY: |