40
40
41
41
from easybuild .framework .easyconfig .easyconfig import resolve_template
42
42
from easybuild .framework .easyconfig .templates import TEMPLATE_NAMES_EASYBLOCK_RUN_STEP , template_constant_dict
43
- from easybuild .tools .build_log import EasyBuildError , EasyBuildExit , raise_nosupport
43
+ from easybuild .tools .build_log import EasyBuildError , EasyBuildExit
44
44
from easybuild .tools .filetools import change_dir
45
45
from easybuild .tools .run import run_shell_cmd
46
46
47
47
48
- def resolve_exts_filter_template (exts_filter , ext ):
48
+ def construct_exts_filter_cmds (exts_filter , ext ):
49
49
"""
50
50
Resolve the exts_filter tuple by replacing the template values using the extension
51
51
:param exts_filter: Tuple of (command, input) using template values (ext_name, ext_version, src)
52
52
:param ext: Instance of Extension or dictionary like with 'name' and optionally 'options', 'version', 'source' keys
53
- :return: (cmd, input) as a tuple of strings
53
+ :return: (cmd, input) as a tuple of strings for each modulename. Might be empty if no filtering is intented
54
54
"""
55
55
56
56
if isinstance (exts_filter , str ) or len (exts_filter ) != 2 :
@@ -61,25 +61,35 @@ def resolve_exts_filter_template(exts_filter, ext):
61
61
if not isinstance (ext , dict ):
62
62
ext = {'name' : ext .name , 'version' : ext .version , 'src' : ext .src , 'options' : ext .options }
63
63
64
- name = ext ['name' ]
65
- if 'options' in ext and 'modulename' in ext ['options' ]:
66
- modname = ext ['options' ]['modulename' ]
67
- else :
68
- modname = name
69
- tmpldict = {
70
- 'ext_name' : modname ,
71
- 'ext_version' : ext .get ('version' ),
72
- 'src' : ext .get ('src' ),
73
- }
74
-
75
64
try :
76
- cmd = cmd % tmpldict
77
- cmdinput = cmdinput % tmpldict if cmdinput else None
78
- except KeyError as err :
79
- msg = "KeyError occurred on completing extension filter template: %s; "
80
- msg += "'name'/'version' keys are no longer supported, should use 'ext_name'/'ext_version' instead"
81
- raise_nosupport (msg % err , '2.0' )
82
- return cmd , cmdinput
65
+ modulenames = ext ['options' ]['modulename' ]
66
+ except KeyError :
67
+ modulenames = [ext ['name' ]]
68
+ else :
69
+ if isinstance (modulenames , list ):
70
+ if not modulenames :
71
+ raise EasyBuildError (f"Empty modulename list for { ext ['name' ]} is not supported."
72
+ "Use `False` to skip checking the module!" )
73
+ elif modulenames is False :
74
+ return [] # Skip any checks
75
+ elif not isinstance (modulenames , str ):
76
+ raise EasyBuildError (f"Wrong type of modulename for { ext ['name' ]} : { type (modulenames )} : { modulenames } " )
77
+ else :
78
+ modulenames = [modulenames ]
79
+
80
+ result = []
81
+ for modulename in modulenames :
82
+ tmpldict = {
83
+ 'ext_name' : modulename ,
84
+ 'ext_version' : ext .get ('version' ),
85
+ 'src' : ext .get ('src' ),
86
+ }
87
+ try :
88
+ result .append ((cmd % tmpldict ,
89
+ cmdinput % tmpldict if cmdinput else None ))
90
+ except KeyError as err :
91
+ raise EasyBuildError (f"KeyError occurred on completing extension filter template: { err } " )
92
+ return result
83
93
84
94
85
95
class Extension (object ):
@@ -287,31 +297,30 @@ def sanity_check_step(self):
287
297
288
298
if exts_filter is None :
289
299
self .log .debug ("no exts_filter setting found, skipping sanitycheck" )
300
+ return res
290
301
291
- if 'modulename' in self .options :
292
- modname = self .options ['modulename' ]
293
- self .log .debug ("modulename found in self.options, using it: %s" , modname )
294
- else :
295
- modname = self .name
296
- self .log .debug ("self.name: %s" , modname )
297
-
302
+ exts_filer_cmds = construct_exts_filter_cmds (exts_filter , self )
298
303
# allow skipping of sanity check by setting module name to False
299
- if modname is False :
304
+ if exts_filer_cmds is None :
300
305
self .log .info ("modulename set to False for '%s' extension, so skipping sanity check" , self .name )
301
- elif exts_filter :
302
- cmd , stdin = resolve_exts_filter_template (exts_filter , self )
303
- cmd_res = run_shell_cmd (cmd , fail_on_error = False , stdin = stdin )
304
-
305
- if cmd_res .exit_code != EasyBuildExit .SUCCESS :
306
- if stdin :
307
- fail_msg = 'command "%s" (stdin: "%s") failed' % (cmd , stdin )
308
- else :
309
- fail_msg = 'command "%s" failed' % cmd
310
- fail_msg += "; output:\n %s" % cmd_res .output .strip ()
306
+ else :
307
+ fail_msgs = []
308
+ for cmd , stdin in exts_filer_cmds :
309
+ cmd_res = run_shell_cmd (cmd , fail_on_error = False , stdin = stdin )
310
+
311
+ if cmd_res .exit_code != EasyBuildExit .SUCCESS :
312
+ if stdin :
313
+ fail_msg = 'command "%s" (stdin: "%s") failed' % (cmd , stdin )
314
+ else :
315
+ fail_msg = 'command "%s" failed' % cmd
316
+ fail_msg += "; output:\n %s" % cmd_res .output .strip ()
317
+ fail_msgs .append (fail_msg )
318
+ if fail_msgs :
319
+ fail_msg = '\n ' .join (fail_msgs )
311
320
self .log .warning ("Sanity check for '%s' extension failed: %s" , self .name , fail_msg )
312
- res = (False , fail_msg )
313
321
# keep track of all reasons of failure
314
322
# (only relevant when this extension is installed stand-alone via ExtensionEasyBlock)
315
323
self .sanity_check_fail_msgs .append (fail_msg )
324
+ res = (False , fail_msg )
316
325
317
326
return res
0 commit comments