Modules: Deduplicate suffixes but don't sort them. (#18351)

* Modules: Deduplicate suffixes but don't sort them.

The suffixes' order is defined by the order in which they appear in the configuration file.

* Modules: Modify tests to use spack_yaml.load_config.

spack_yaml.load_config ensures that the configuration is stored in an ordered manner. Without this change, the behavior of the tests did not match Spack's.

* Modules: Tweak the suffixes test to better catch ordering issues.
This commit is contained in:
Rémi Lacroix 2020-09-08 16:43:03 +02:00 committed by GitHub
parent c2b33b4444
commit 92bf9493cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View File

@ -36,6 +36,7 @@
import re import re
import llnl.util.filesystem import llnl.util.filesystem
from llnl.util.lang import dedupe
import llnl.util.tty as tty import llnl.util.tty as tty
import spack.build_environment as build_environment import spack.build_environment as build_environment
import spack.error import spack.error
@ -442,7 +443,7 @@ def suffixes(self):
for constraint, suffix in self.conf.get('suffixes', {}).items(): for constraint, suffix in self.conf.get('suffixes', {}).items():
if constraint in self.spec: if constraint in self.spec:
suffixes.append(suffix) suffixes.append(suffix)
suffixes = sorted(set(suffixes)) suffixes = list(dedupe(suffixes))
if self.hash: if self.hash:
suffixes.append(self.hash) suffixes.append(self.hash)
return suffixes return suffixes

View File

@ -16,7 +16,6 @@
import py import py
import pytest import pytest
import ruamel.yaml as yaml
from llnl.util.filesystem import mkdirp, remove_linked_tree from llnl.util.filesystem import mkdirp, remove_linked_tree
@ -35,6 +34,7 @@
import spack.stage import spack.stage
import spack.util.executable import spack.util.executable
import spack.util.gpg import spack.util.gpg
import spack.util.spack_yaml as syaml
from spack.util.pattern import Bunch from spack.util.pattern import Bunch
from spack.fetch_strategy import FetchStrategyComposite, URLFetchStrategy from spack.fetch_strategy import FetchStrategyComposite, URLFetchStrategy
@ -748,7 +748,7 @@ def _impl(filename):
file = os.path.join(root_for_conf, filename + '.yaml') file = os.path.join(root_for_conf, filename + '.yaml')
with open(file) as f: with open(file) as f:
configuration = yaml.load(f) configuration = syaml.load_config(f)
def mock_config_function(): def mock_config_function():
return configuration return configuration

View File

@ -3,6 +3,7 @@ enable:
tcl: tcl:
mpileaks: mpileaks:
suffixes: suffixes:
'+opt': baz
'+debug': foo '+debug': foo
'~debug': bar
'^mpich': foo '^mpich': foo
'~debug': bar

View File

@ -272,7 +272,11 @@ def test_suffixes(self, module_configuration, factory):
assert 'foo-foo' not in writer.layout.use_name assert 'foo-foo' not in writer.layout.use_name
writer, spec = factory('mpileaks~debug arch=x86-linux') writer, spec = factory('mpileaks~debug arch=x86-linux')
assert 'bar-foo' in writer.layout.use_name assert 'foo-bar' in writer.layout.use_name
assert 'baz' not in writer.layout.use_name
writer, spec = factory('mpileaks~debug+opt arch=x86-linux')
assert 'baz-foo-bar' in writer.layout.use_name
def test_setup_environment(self, modulefile_content, module_configuration): def test_setup_environment(self, modulefile_content, module_configuration):
"""Tests the internal set-up of run-time environment.""" """Tests the internal set-up of run-time environment."""