4141* Victor Holanda (CSCS, ETH Zurich)
4242"""
4343
44+ import contextlib
4445import copy
4546import difflib
4647import functools
@@ -199,8 +200,7 @@ def triage_easyconfig_params(variables, ec):
199200
200201 for key in variables :
201202 # validations are skipped, just set in the config
202- if any (key in d for d in (ec , DEPRECATED_EASYCONFIG_PARAMETERS .keys (),
203- ALTERNATIVE_EASYCONFIG_PARAMETERS .keys ())):
203+ if any (key in d for d in (ec , DEPRECATED_EASYCONFIG_PARAMETERS , ALTERNATIVE_EASYCONFIG_PARAMETERS )):
204204 ec_params [key ] = variables [key ]
205205 _log .debug ("setting config option %s: value %s (type: %s)" , key , ec_params [key ], type (ec_params [key ]))
206206 elif key in REPLACED_PARAMETERS :
@@ -728,7 +728,7 @@ def update(self, key, value, allow_duplicate=True):
728728 # Overwrite easyconfig parameter value with updated value, preserving type
729729 self [key ] = param_value
730730
731- def set_keys (self , params ):
731+ def set_keys (self , params : dict ):
732732 """
733733 Set keys in this EasyConfig instance based on supplied easyconfig parameter values.
734734
@@ -739,15 +739,15 @@ def set_keys(self, params):
739739 # disable templating when setting easyconfig parameters
740740 # required to avoid problems with values that need more parsing to be done (e.g. dependencies)
741741 with self .disable_templating ():
742- for key in sorted (params .keys ()):
742+ for key , value in sorted (params .items ()):
743743 # validations are skipped, just set in the config
744- if any (key in x . keys () for x in (self ._config , ALTERNATIVE_EASYCONFIG_PARAMETERS ,
745- DEPRECATED_EASYCONFIG_PARAMETERS )):
746- self [key ] = params [ key ]
744+ if any (key in x for x in (self ._config , ALTERNATIVE_EASYCONFIG_PARAMETERS ,
745+ DEPRECATED_EASYCONFIG_PARAMETERS )):
746+ self [key ] = value
747747 self .log .info ("setting easyconfig parameter %s: value %s (type: %s)" ,
748748 key , self [key ], type (self [key ]))
749749 else :
750- raise EasyBuildError ("Unknown easyconfig parameter: %s (value '%s')" , key , params [ key ] )
750+ raise EasyBuildError ("Unknown easyconfig parameter: %s (value '%s')" , key , value )
751751
752752 def parse (self ):
753753 """
@@ -2202,15 +2202,18 @@ def resolve_template(value, tmpl_dict, expect_resolved=True):
22022202 try :
22032203 orig_value = value
22042204 # map old templates to new values for alternative and deprecated templates
2205- alt_map = {old_tmpl : tmpl_dict [new_tmpl ] for (old_tmpl , new_tmpl ) in
2206- ALTERNATIVE_EASYCONFIG_TEMPLATES .items () if new_tmpl in tmpl_dict .keys ()}
2207- alt_map2 = {new_tmpl : tmpl_dict [old_tmpl ] for (old_tmpl , new_tmpl ) in
2208- ALTERNATIVE_EASYCONFIG_TEMPLATES .items () if old_tmpl in tmpl_dict .keys ()}
2209- depr_map = {old_tmpl : tmpl_dict [new_tmpl ] for (old_tmpl , (new_tmpl , ver )) in
2210- DEPRECATED_EASYCONFIG_TEMPLATES .items () if new_tmpl in tmpl_dict .keys ()}
2205+ new_tmpl_dict = tmpl_dict .copy ()
2206+ with contextlib .suppress (KeyError ):
2207+ new_tmpl_dict .update ({old_tmpl : tmpl_dict [new_tmpl ]
2208+ for (old_tmpl , new_tmpl ) in ALTERNATIVE_EASYCONFIG_TEMPLATES .items ()})
2209+ new_tmpl_dict .update ({new_tmpl : tmpl_dict [old_tmpl ]
2210+ for (old_tmpl , new_tmpl ) in ALTERNATIVE_EASYCONFIG_TEMPLATES .items ()})
2211+ depr_map = {old_tmpl : tmpl_dict [new_tmpl ]
2212+ for (old_tmpl , new_tmpl ) in DEPRECATED_EASYCONFIG_TEMPLATES .items ()}
2213+ new_tmpl_dict .update (depr_map )
22112214
22122215 # try templating with alternative and deprecated templates included
2213- value = value % { ** tmpl_dict , ** alt_map , ** alt_map2 , ** depr_map }
2216+ value = value % new_tmpl_dict
22142217
22152218 for old_tmpl , val in depr_map .items ():
22162219 # check which deprecated templates were replaced, and issue deprecation warnings
0 commit comments