backwards compatibility for naming scheme (#16812)
* backwards compatibility for naming scheme
This commit is contained in:
parent
c01433f60a
commit
e9dcab9464
@ -397,8 +397,13 @@ def __init__(self, spec):
|
||||
@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
|
||||
|
@ -17,7 +17,8 @@
|
||||
#: 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 @@
|
||||
'type': 'boolean',
|
||||
'default': False
|
||||
},
|
||||
'naming_scheme': {
|
||||
'type': 'string' # Can we be more specific here?
|
||||
},
|
||||
'projections': projections_scheme,
|
||||
'all': module_file_configuration,
|
||||
}
|
||||
|
4
lib/spack/spack/test/data/modules/tcl/naming_scheme.yaml
Normal file
4
lib/spack/spack/test/data/modules/tcl/naming_scheme.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
enable:
|
||||
- tcl
|
||||
tcl:
|
||||
naming_scheme: '{name}/{version}-{compiler.name}'
|
@ -142,6 +142,20 @@ def test_blacklist(self, modulefile_content, module_configuration):
|
||||
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."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user