backwards compatibility for naming scheme (#16812)

* backwards compatibility for naming scheme
This commit is contained in:
Greg Becker 2020-05-26 14:06:25 -07:00 committed by GitHub
parent c01433f60a
commit e9dcab9464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View File

@ -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

View File

@ -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,
}

View File

@ -0,0 +1,4 @@
enable:
- tcl
tcl:
naming_scheme: '{name}/{version}-{compiler.name}'

View File

@ -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."""