Skip to content

Commit

Permalink
Only add extensions in module file if there are extensions
Browse files Browse the repository at this point in the history
This fixes easybuilders#4330.
  • Loading branch information
wpoely86 committed Aug 16, 2023
1 parent ac91659 commit 33d354c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 12 additions & 4 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,16 +1727,24 @@ def _make_extension_list(self):
# Each extension in exts_list is either a string or a list/tuple with name, version as first entries
return [(ext, ) if isinstance(ext, string_type) else ext[:2] for ext in self.cfg.get_ref('exts_list')]

def make_extension_string(self, name_version_sep='-', ext_sep=', ', sort=True):
def make_extension_list(self, name_version_sep='-', sort=True):
"""
Generate a string with a list of extensions.
Generate a list of extensions.
The name and version are separated by name_version_sep and each extension is separated by ext_sep
The name and version are separated by name_version_sep
"""
exts_list = (name_version_sep.join(ext) for ext in self._make_extension_list())
if sort:
exts_list = sorted(exts_list, key=str.lower)
return ext_sep.join(exts_list)
return exts_list

def make_extension_string(self, name_version_sep='-', ext_sep=', ', sort=True):
"""
Generate a string with a list of extensions.
The name and version are separated by name_version_sep and each extension is separated by ext_sep
"""
return ext_sep.join(self.make_extension_list(name_version_sep=name_version_sep, sort=sort))

def prepare_for_extensions(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def _generate_extensions_list(self):
"""
Generate a list of all extensions in name/version format
"""
return self.app.make_extension_string(name_version_sep='/', ext_sep=',').split(',')
return self.app.make_extension_list(name_version_sep='/')

def _generate_help_text(self):
"""
Expand Down
10 changes: 10 additions & 0 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,16 @@ def test_module_extensions(self):
regex = re.compile(pattern, re.M)
self.assertTrue(regex.search(desc), "Pattern '%s' found in: %s" % (regex.pattern, desc))

# check if the extensions is missing if there are no extensions
test_ec = os.path.join(test_dir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0-test.eb')

ec = EasyConfig(test_ec)
eb = EasyBlock(ec)
modgen = self.MODULE_GENERATOR_CLASS(eb)
desc = modgen.get_description()

self.assertFalse(re.search("\s*extensions\(", desc), "No extensions found in: %s" % desc)

def test_prepend_paths(self):
"""Test generating prepend-paths statements."""
# test prepend_paths
Expand Down

0 comments on commit 33d354c

Please sign in to comment.