Skip to content

Commit d0eb465

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 6384067 commit d0eb465

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
@@ -47,21 +47,13 @@
4747
from easybuild.tools.utilities import trace_msg
4848

4949

50-
def construct_exts_filter_cmds(exts_filter, ext):
51-
"""
52-
Resolve the exts_filter tuple by replacing the template values using the extension
53-
:param exts_filter: Tuple of (command, input) using template values (ext_name, ext_version, src)
50+
def get_modulenames(ext, use_name_for_false):
51+
"""Return a list of modulenames for the extension
5452
:param ext: Instance of Extension or dictionary like with 'name' and optionally 'options', 'version', 'source' keys
55-
:return: (cmd, input) as a tuple of strings for each modulename. Might be empty if no filtering is intented
53+
:param use_name_for_false: Whether to return a list with the name or an empty list when the modulename is False
5654
"""
57-
58-
if isinstance(exts_filter, str) or len(exts_filter) != 2:
59-
raise EasyBuildError('exts_filter should be a list or tuple of ("command","input")')
60-
61-
cmd, cmdinput = exts_filter
62-
6355
if not isinstance(ext, dict):
64-
ext = {'name': ext.name, 'version': ext.version, 'src': ext.src, 'options': ext.options}
56+
ext = {'name': ext.name, 'options': ext.options}
6557

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

8294
result = []
8395
for modulename in modulenames:

0 commit comments

Comments
 (0)