Skip to content

Commit

Permalink
Merge pull request easybuilders#4417 from xdelaruelle/modules_hidden
Browse files Browse the repository at this point in the history
use `--all` option with EnvironmentModules v4.6+ to get available hidden modules
  • Loading branch information
boegel authored Jan 3, 2024
2 parents d7cd5e3 + 2d5db91 commit 415cbcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 19 additions & 2 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,14 +1283,14 @@ def tweak_stdout(txt):

return super(EnvironmentModulesTcl, self).run_module(*args, **kwargs)

def available(self, mod_name=None):
def available(self, mod_name=None, extra_args=None):
"""
Return a list of available modules for the given (partial) module name;
use None to obtain a list of all available modules.
:param mod_name: a (partial) module name for filtering (default: None)
"""
mods = super(EnvironmentModulesTcl, self).available(mod_name=mod_name)
mods = super(EnvironmentModulesTcl, self).available(mod_name=mod_name, extra_args=extra_args)
# strip off slash at beginning, if it's there
# under certain circumstances, 'modulecmd.tcl avail' (DEISA variant) spits out available modules like this
clean_mods = [mod.lstrip(os.path.sep) for mod in mods]
Expand Down Expand Up @@ -1328,6 +1328,8 @@ class EnvironmentModules(EnvironmentModulesTcl):
MAX_VERSION = None
VERSION_REGEXP = r'^Modules\s+Release\s+(?P<version>\d[^+\s]*)(\+\S*)?\s'

SHOW_HIDDEN_OPTION = '--all'

def __init__(self, *args, **kwargs):
"""Constructor, set Environment Modules-specific class variable values."""
# ensure in-depth modulepath search (MODULES_AVAIL_INDEPTH has been introduced in v4.3)
Expand Down Expand Up @@ -1383,6 +1385,21 @@ def check_module_output(self, cmd, stdout, stderr):
else:
self.log.debug("No errors detected when running module command '%s'", cmd)

def available(self, mod_name=None, extra_args=None):
"""
Return a list of available modules for the given (partial) module name;
use None to obtain a list of all available modules.
:param mod_name: a (partial) module name for filtering (default: None)
"""
if extra_args is None:
extra_args = []
# make hidden modules visible (requires Environment Modules 4.6.0)
if StrictVersion(self.version) >= StrictVersion('4.6.0'):
extra_args.append(self.SHOW_HIDDEN_OPTION)

return super(EnvironmentModules, self).available(mod_name=mod_name, extra_args=extra_args)

def get_setenv_value_from_modulefile(self, mod_name, var_name):
"""
Get value for specific 'setenv' statement from module file for the specified module.
Expand Down
6 changes: 6 additions & 0 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ def test_avail(self):
self.assertIn('bzip2/.1.0.6', ms)
self.assertIn('toy/.0.0-deps', ms)
self.assertIn('OpenMPI/.2.1.2-GCC-6.4.0-2.28', ms)
elif (isinstance(self.modtool, EnvironmentModules)
and StrictVersion(self.modtool.version) >= StrictVersion('4.6.0')):
# bzip2/.1.0.6 is not there, since that's a module file in Lua syntax
self.assertEqual(len(ms), TEST_MODULES_COUNT + 2)
self.assertIn('toy/.0.0-deps', ms)
self.assertIn('OpenMPI/.2.1.2-GCC-6.4.0-2.28', ms)
else:
self.assertEqual(len(ms), TEST_MODULES_COUNT)

Expand Down

0 comments on commit 415cbcd

Please sign in to comment.