From 2202ce27fa03010630ab81ea5d8679503346cf7a Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Sat, 15 May 2021 09:19:10 -0700 Subject: [PATCH] do not sort projections alphabetically (#23649) * do not sort projections alphabetically * add assertion for ordered dict --- lib/spack/spack/environment.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index a37cad8633..979e14e8c9 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -9,6 +9,7 @@ import shutil import copy import six +import ruamel.yaml as yaml from ordereddict_backport import OrderedDict @@ -478,9 +479,12 @@ def __eq__(self, other): def to_dict(self): ret = syaml.syaml_dict([('root', self.root)]) if self.projections: - projections_dict = syaml.syaml_dict( - sorted(self.projections.items())) - ret['projections'] = projections_dict + # projections guaranteed to be ordered dict if true-ish + # for python2.6, may be syaml or ruamel.yaml implementation + # so we have to check for both + types = (OrderedDict, syaml.syaml_dict, yaml.comments.CommentedMap) + assert isinstance(self.projections, types) + ret['projections'] = self.projections if self.select: ret['select'] = self.select if self.exclude: