Skip to content

Commit 7dac45e

Browse files
committed
Factor out method to get modulename(s)
This might be useful for easyblocks to avoid duplicating the code for determining the modulename from either the options or the name.
1 parent a5f5247 commit 7dac45e

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

easybuild/framework/extension.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,13 @@
4545
from easybuild.tools.run import run_shell_cmd
4646

4747

48-
def construct_exts_filter_cmds(exts_filter, ext):
49-
"""
50-
Resolve the exts_filter tuple by replacing the template values using the extension
51-
:param exts_filter: Tuple of (command, input) using template values (ext_name, ext_version, src)
48+
def get_modulenames(ext, use_name_for_false):
49+
"""Return a list of modulenames for the extension
5250
: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 for each modulename. Might be empty if no filtering is intented
51+
:param use_name_for_false: Whether to return a list with the name or an empty list when the modulename is False
5452
"""
55-
56-
if isinstance(exts_filter, str) or len(exts_filter) != 2:
57-
raise EasyBuildError('exts_filter should be a list or tuple of ("command","input")')
58-
59-
cmd, cmdinput = exts_filter
60-
6153
if not isinstance(ext, dict):
62-
ext = {'name': ext.name, 'version': ext.version, 'src': ext.src, 'options': ext.options}
54+
ext = {'name': ext.name, 'options': ext.options}
6355

6456
try:
6557
modulenames = ext['options']['modulename']
@@ -71,11 +63,31 @@ def construct_exts_filter_cmds(exts_filter, ext):
7163
raise EasyBuildError(f"Empty modulename list for {ext['name']} is not supported."
7264
"Use `False` to skip checking the module!")
7365
elif modulenames is False:
74-
return [] # Skip any checks
66+
return [ext['name']] if use_name_for_false else []
7567
elif not isinstance(modulenames, str):
7668
raise EasyBuildError(f"Wrong type of modulename for {ext['name']}: {type(modulenames)}: {modulenames}")
7769
else:
7870
modulenames = [modulenames]
71+
return modulenames
72+
73+
74+
def construct_exts_filter_cmds(exts_filter, ext):
75+
"""
76+
Resolve the exts_filter tuple by replacing the template values using the extension
77+
:param exts_filter: Tuple of (command, input) using template values (ext_name, ext_version, src)
78+
:param ext: Instance of Extension or dictionary like with 'name' and optionally 'options', 'version', 'source' keys
79+
:return: (cmd, input) as a tuple of strings for each modulename. Might be empty if no filtering is intented
80+
"""
81+
82+
if isinstance(exts_filter, str) or len(exts_filter) != 2:
83+
raise EasyBuildError('exts_filter should be a list or tuple of ("command","input")')
84+
85+
cmd, cmdinput = exts_filter
86+
87+
if not isinstance(ext, dict):
88+
ext = {'name': ext.name, 'version': ext.version, 'src': ext.src, 'options': ext.options}
89+
90+
modulenames = get_modulenames(ext, use_name_for_false=False)
7991

8092
result = []
8193
for modulename in modulenames:

0 commit comments

Comments
 (0)