diff options
-rw-r--r-- | lib/spack/spack/config.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/modules.py | 30 | ||||
-rw-r--r-- | lib/spack/spack/test/modules.py | 18 |
3 files changed, 37 insertions, 13 deletions
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 1ac8a01619..71cdff09ea 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -276,7 +276,7 @@ section_schemas = { }, 'autoload': {'$ref': '#/definitions/dependency_selection'}, 'prerequisites': {'$ref': '#/definitions/dependency_selection'}, - 'conflict': {'type': 'string'}, + 'conflict': {'$ref': '#/definitions/array_of_strings'}, 'environment': { 'type': 'object', 'default': {}, diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index bcccf2f9b8..57a4a2c754 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -46,6 +46,7 @@ import os import os.path import re import textwrap +import string import llnl.util.tty as tty import spack @@ -499,15 +500,20 @@ class TclModule(EnvModule): def module_specific_content(self, configuration): naming_tokens = self.tokens # Conflict - conflict_format = configuration.get('conflict', '') - if conflict_format: - for naming_dir, conflict_dir in zip(self.naming_scheme.split('/'), conflict_format.split('/')): - if naming_dir != conflict_dir: - message = 'Conflict scheme does not match naming scheme [{spec}]\n\n' - message += 'naming scheme : "{nformat}"\n' - message += 'conflict scheme : "{cformat}"\n' - raise tty.error( - message.format(spec=self.spec, nformat=self.naming_scheme, cformat=conflict_format) - ) - conflict_format = 'conflict ' + conflict_format - yield conflict_format.format(**naming_tokens) + conflict_format = configuration.get('conflict', []) + f = string.Formatter() + for item in conflict_format: + line = 'conflict ' + item + '\n' + if len([x for x in f.parse(line)]) > 1: # We do have placeholder to substitute + for naming_dir, conflict_dir in zip(self.naming_scheme.split('/'), item.split('/')): + if naming_dir != conflict_dir: + message = 'conflict scheme does not match naming scheme [{spec}]\n\n' + message += 'naming scheme : "{nformat}"\n' + message += 'conflict scheme : "{cformat}"\n\n' + message += '** You may want to check your `modules.yaml` configuration file **\n' + tty.error( + message.format(spec=self.spec, nformat=self.naming_scheme, cformat=item) + ) + raise SystemExit('Module generation aborted.') + line = line.format(**naming_tokens) + yield line diff --git a/lib/spack/spack/test/modules.py b/lib/spack/spack/test/modules.py index 21afa355e7..704700417b 100644 --- a/lib/spack/spack/test/modules.py +++ b/lib/spack/spack/test/modules.py @@ -62,6 +62,16 @@ configuration_blacklist = { } } +configuration_conflicts = { + 'enable': ['tcl'], + 'tcl': { + 'naming_scheme': '{name}/{version}-{compiler.name}', + 'all': { + 'conflict': ['{name}', 'intel/14.0.1'] + } + } +} + from spack.test.mock_packages_test import MockPackagesTest @@ -124,3 +134,11 @@ class TclTests(MockPackagesTest): content = self.get_modulefile_content(spec) self.assertEqual(len([x for x in content if 'is-loaded' in x]), 1) self.assertEqual(len([x for x in content if 'module load ' in x]), 1) + + def test_conflicts(self): + spack.modules.CONFIGURATION = configuration_conflicts + spec = spack.spec.Spec('mpileaks=x86-linux') + content = self.get_modulefile_content(spec) + self.assertEqual(len([x for x in content if x.startswith('conflict')]), 2) + self.assertEqual(len([x for x in content if x == 'conflict mpileaks']), 1) + self.assertEqual(len([x for x in content if x == 'conflict intel/14.0.1']), 1) |