Skip to content

Commit

Permalink
reinstate fallback to ModulesTool.module_wrapper_exists in ModulesToo…
Browse files Browse the repository at this point in the history
…l.exist (fixes easybuilders#3335)
  • Loading branch information
boegel committed May 16, 2020
1 parent 018337e commit 522bb6e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
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
13 changes: 8 additions & 5 deletions test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,12 @@ 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:
# module-version only works for EnvironmentModules(C), not with EnvironmentModulesTcl;
# for Lmod, 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
if 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])
Expand Down Expand Up @@ -354,8 +357,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

0 comments on commit 522bb6e

Please sign in to comment.