diff options
-rw-r--r-- | lib/spack/spack/modules/common.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/schema/modules.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/test/data/modules/tcl/naming_scheme.yaml | 4 | ||||
-rw-r--r-- | lib/spack/spack/test/modules/tcl.py | 14 |
4 files changed, 30 insertions, 3 deletions
diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py index 7eca9292c9..95ef81415e 100644 --- a/lib/spack/spack/modules/common.py +++ b/lib/spack/spack/modules/common.py @@ -397,8 +397,13 @@ class BaseConfiguration(object): @property def projections(self): """Projection from specs to module names""" - projections = self.module.configuration().get( - 'projections', self.default_projections) + # backwards compatiblity for naming_scheme key + conf = self.module.configuration() + if 'naming_scheme' in conf: + default = {'all': conf['naming_scheme']} + else: + default = self.default_projections + projections = conf.get('projections', default) # Ensure the named tokens we are expanding are allowed, see # issue #2884 for reference diff --git a/lib/spack/spack/schema/modules.py b/lib/spack/spack/schema/modules.py index ac9237609b..d03dbfb410 100644 --- a/lib/spack/spack/schema/modules.py +++ b/lib/spack/spack/schema/modules.py @@ -17,7 +17,8 @@ import spack.schema.projections #: THIS NEEDS TO BE UPDATED FOR EVERY NEW KEYWORD THAT #: IS ADDED IMMEDIATELY BELOW THE MODULE TYPE ATTRIBUTE spec_regex = r'(?!hierarchy|core_specs|verbose|hash_length|whitelist|' \ - r'blacklist|projections|core_compilers|all)(^\w[\w-]*)' + r'blacklist|projections|naming_scheme|core_compilers|all)' \ + r'(^\w[\w-]*)' #: Matches an anonymous spec, i.e. a spec without a root name anonymous_spec_regex = r'^[\^@%+~]' @@ -94,6 +95,9 @@ module_type_configuration = { 'type': 'boolean', 'default': False }, + 'naming_scheme': { + 'type': 'string' # Can we be more specific here? + }, 'projections': projections_scheme, 'all': module_file_configuration, } diff --git a/lib/spack/spack/test/data/modules/tcl/naming_scheme.yaml b/lib/spack/spack/test/data/modules/tcl/naming_scheme.yaml new file mode 100644 index 0000000000..cc4cf8f782 --- /dev/null +++ b/lib/spack/spack/test/data/modules/tcl/naming_scheme.yaml @@ -0,0 +1,4 @@ +enable: + - tcl +tcl: + naming_scheme: '{name}/{version}-{compiler.name}' diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py index 98d9363f87..7672cdc676 100644 --- a/lib/spack/spack/test/modules/tcl.py +++ b/lib/spack/spack/test/modules/tcl.py @@ -142,6 +142,20 @@ class TestTcl(object): assert len([x for x in content if 'is-loaded' in x]) == 1 assert len([x for x in content if 'module load ' in x]) == 1 + def test_naming_scheme_compat(self, factory, module_configuration): + """Tests backwards compatibility for naming_scheme key""" + module_configuration('naming_scheme') + + # Test we read the expected configuration for the naming scheme + writer, _ = factory('mpileaks') + expected = { + 'all': '{name}/{version}-{compiler.name}' + } + + assert writer.conf.projections == expected + projection = writer.spec.format(writer.conf.projections['all']) + assert projection in writer.layout.use_name + def test_projections_specific(self, factory, module_configuration): """Tests reading the correct naming scheme.""" |