Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,7 @@ def module_wrapper_exists(self, mod_name, modulerc_fn='.modulerc', mod_wrapper_r
"""
Determine whether a module wrapper with specified name exists.
Only .modulerc file in Tcl syntax is considered here.
DEPRECATED. Use exists()
"""
self.log.deprecated('module_wrapper_exists is unreliable and should no longer be used. ' +
'Use exists instead to check for an existing module or alias.', '5.0')

if mod_wrapper_regex_template is None:
mod_wrapper_regex_template = "^[ ]*module-version (?P<wrapped_mod>[^ ]*) %s$"
Expand Down Expand Up @@ -590,6 +587,19 @@ def mod_exists_via_show(mod_name):
self.log.debug("checking whether hidden module %s exists via 'show'..." % mod_name)
mod_exists = mod_exists_via_show(mod_name)

# if no module file was found, check whether specified module name can be a 'wrapper' module...
# this fallback mechanism is important when using a hierarchical module naming scheme,
# where "full" module names (like Core/Java/11) are used to check whether modules exist already;
# Lmod will report module wrappers as non-existent when full module name is used,
# see https://github.com/TACC/Lmod/issues/446
if not mod_exists:
self.log.debug("Module %s not found via module avail/show, checking whether it is a wrapper", mod_name)
wrapped_mod = self.module_wrapper_exists(mod_name)
if wrapped_mod is not None:
# module wrapper only really exists if the wrapped module file is also available
mod_exists = wrapped_mod in avail_mod_names or mod_exists_via_show(wrapped_mod)
self.log.debug("Result for existence check of wrapped module %s: %s", wrapped_mod, mod_exists)

self.log.debug("Result for existence check of %s module: %s", mod_name, mod_exists)

mods_exist.append(mod_exists)
Expand Down Expand Up @@ -1407,7 +1417,7 @@ def prepend_module_path(self, path, set_mod_paths=True, priority=None):
def module_wrapper_exists(self, mod_name):
"""
Determine whether a module wrapper with specified name exists.
DEPRECATED. Use exists()
First check for wrapper defined in .modulerc.lua, fall back to also checking .modulerc (Tcl syntax).
"""
res = None

Expand Down
15 changes: 7 additions & 8 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,11 @@ def test_exist(self):

self.assertTrue('Core/Java/1.8.0_181' in self.modtool.available())
self.assertEqual(self.modtool.exist(['Core/Java/1.8.0_181']), [True])
# module-version only works for EnvironmentModules(C) as LMod and EnvironmentModulesTcl would need updating
# to full path, see https://github.com/TACC/Lmod/issues/446
if isinstance(self.modtool, Lmod) or self.modtool.__class__ == EnvironmentModulesTcl:
self.assertEqual(self.modtool.exist(['Core/Java/1.8', 'Core/Java/site_default']), [False, False])
else:
self.assertEqual(self.modtool.exist(['Core/Java/1.8', 'Core/Java/site_default']), [True, True])
# there's a workaround to ensure that module wrappers/aliases are recognized when they're
# being checked with the full module name (see https://github.com/TACC/Lmod/issues/446);
# that's necessary when using a hierarchical module naming scheme,
# see https://github.com/easybuilders/easybuild-framework/issues/3335
self.assertEqual(self.modtool.exist(['Core/Java/1.8', 'Core/Java/site_default']), [True, True])

# also check with .modulerc.lua for Lmod 7.8 or newer
if isinstance(self.modtool, Lmod) and StrictVersion(self.modtool.version) >= StrictVersion('7.8'):
Expand Down Expand Up @@ -354,8 +353,8 @@ def test_exist(self):
shutil.move(java_mod_dir, os.path.join(self.test_prefix, 'Core', 'Java'))
self.assertTrue('Core/Java/1.8.0_181' in self.modtool.available())
self.assertEqual(self.modtool.exist(['Core/Java/1.8.0_181']), [True])
self.assertEqual(self.modtool.exist(['Core/Java/1.8']), [False])
self.assertEqual(self.modtool.exist(['Core/Java/site_default']), [False])
self.assertEqual(self.modtool.exist(['Core/Java/1.8']), [True])
self.assertEqual(self.modtool.exist(['Core/Java/site_default']), [True])

# Test alias in home directory .modulerc
if isinstance(self.modtool, Lmod) and StrictVersion(self.modtool.version) >= StrictVersion('7.0'):
Expand Down