From 4600d106e27caa87b8206e9db7af825f16c93fc0 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 22 Aug 2017 23:20:19 +0200 Subject: Config scopes are now returning OrderedDicts instead of dicts. (#5183) It seems 8f21332fec4c8adb5349ff90e30bb0e4f75e090e introduced a bug in that normal dictionaries are returned from ConfigScope objects instead of OrderedDicts. This is fixed here. --- lib/spack/spack/config.py | 6 ++-- lib/spack/spack/test/config.py | 28 ++++++++++++++++++ lib/spack/spack/test/data/config/modules.yaml | 42 +++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 lib/spack/spack/test/data/config/modules.yaml (limited to 'lib') diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index d3a385ea80..8b7fcf334c 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -162,7 +162,7 @@ class ConfigScope(object): def __init__(self, name, path): self.name = name # scope name. self.path = path # path to directory containing configs. - self.sections = {} # sections read from config files. + self.sections = syaml.syaml_dict() # sections read from config files. # Register in a dict of all ConfigScopes # TODO: make this cleaner. Mocking up for testing is brittle. @@ -197,7 +197,7 @@ class ConfigScope(object): def clear(self): """Empty cached config information.""" - self.sections = {} + self.sections = syaml.syaml_dict() def __repr__(self): return '' % (self.name, self.path) @@ -314,7 +314,7 @@ def _mark_overrides(data): return [_mark_overrides(elt) for elt in data] elif isinstance(data, dict): - marked = {} + marked = syaml.syaml_dict() for key, val in iteritems(data): if isinstance(key, string_types) and key.endswith(':'): key = syaml.syaml_str(key[:-1]) diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index 2363754a00..d00dc64bb3 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -369,3 +369,31 @@ class TestConfig(object): 'install_tree': 'install_tree_path', 'build_stage': ['patha', 'pathb'] } + + +def test_keys_are_ordered(): + + expected_order = ( + 'bin', + 'man', + 'share/man', + 'share/aclocal', + 'lib', + 'lib64', + 'include', + 'lib/pkgconfig', + 'lib64/pkgconfig', + '' + ) + + config_scope = spack.config.ConfigScope( + 'modules', + os.path.join(spack.test_path, 'data', 'config') + ) + + data = config_scope.get_section('modules') + + prefix_inspections = data['modules']['prefix_inspections'] + + for actual, expected in zip(prefix_inspections, expected_order): + assert actual == expected diff --git a/lib/spack/spack/test/data/config/modules.yaml b/lib/spack/spack/test/data/config/modules.yaml new file mode 100644 index 0000000000..25fe2088e7 --- /dev/null +++ b/lib/spack/spack/test/data/config/modules.yaml @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------- +# This is the default configuration for Spack's module file generation. +# +# Settings here are versioned with Spack and are intended to provide +# sensible defaults out of the box. Spack maintainers should edit this +# file to keep it current. +# +# Users can override these settings by editing the following files. +# +# Per-spack-instance settings (overrides defaults): +# $SPACK_ROOT/etc/spack/modules.yaml +# +# Per-user settings (overrides default and site settings): +# ~/.spack/modules.yaml +# ------------------------------------------------------------------------- +modules: + enable: + - tcl + - dotkit + prefix_inspections: + bin: + - PATH + man: + - MANPATH + share/man: + - MANPATH + share/aclocal: + - ACLOCAL_PATH + lib: + - LIBRARY_PATH + - LD_LIBRARY_PATH + lib64: + - LIBRARY_PATH + - LD_LIBRARY_PATH + include: + - CPATH + lib/pkgconfig: + - PKG_CONFIG_PATH + lib64/pkgconfig: + - PKG_CONFIG_PATH + '': + - CMAKE_PREFIX_PATH -- cgit v1.2.3-70-g09d2