Skip to content

Commit 2ca3cf4

Browse files
authored
Merge pull request #3337 from boegel/fix_module_wrapper_hmns
reinstate fallback to ModulesTool.module_wrapper_exists in ModulesTool.exist
2 parents b6b409b + 4f61f78 commit 2ca3cf4

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

easybuild/tools/modules.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,7 @@ def module_wrapper_exists(self, mod_name, modulerc_fn='.modulerc', mod_wrapper_r
487487
"""
488488
Determine whether a module wrapper with specified name exists.
489489
Only .modulerc file in Tcl syntax is considered here.
490-
DEPRECATED. Use exists()
491490
"""
492-
self.log.deprecated('module_wrapper_exists is unreliable and should no longer be used. ' +
493-
'Use exists instead to check for an existing module or alias.', '5.0')
494491

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

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

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

test/framework/modules.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,11 @@ def test_exist(self):
318318

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

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

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

0 commit comments

Comments
 (0)