Skip to content

Commit

Permalink
also check for module wrappers in 'ModulesTool.exist' method (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Oct 2, 2018
1 parent 723932e commit dc8d1f5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
17 changes: 15 additions & 2 deletions easybuild/tools/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ def mod_exists_via_show(mod_name):
txt = self.show(mod_name)
return bool(re.search(mod_exists_regex, txt, re.M))

def mod_exists_wrapper(mod_name):
"""
Helper function to check whether specified module name is a wrapper module.
"""
return False # FIXME

if skip_avail:
avail_mod_names = []
elif len(mod_names) == 1:
Expand All @@ -491,11 +497,18 @@ def mod_exists_via_show(mod_name):
for (mod_name, visible) in mod_names:
if visible:
# module name may be partial, so also check via 'module show' as fallback
mods_exist.append(mod_name in avail_mod_names or mod_exists_via_show(mod_name))
mod_exists = mod_name in avail_mod_names or mod_exists_via_show(mod_name)
else:
# hidden modules are not visible in 'avail', need to use 'show' instead
self.log.debug("checking whether hidden module %s exists via 'show'..." % mod_name)
mods_exist.append(mod_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...
if not mod_exists:
self.log.debug("Module %s not found via module avail/show, checking whether it's an existing wrapper")
mod_exists = mod_exists_wrapper(mod_name)

mods_exist.append(mod_exists)

return mods_exist

Expand Down
23 changes: 22 additions & 1 deletion test/framework/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def test_exists(self):
self.assertEqual(self.modtool.exist(['OpenMPI/1.6.4'], skip_avail=True), [False])

# exists works on hidden modules in Lua syntax (only with Lmod)
test_modules_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))
if isinstance(self.modtool, Lmod):
test_modules_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))
# make sure only the .lua module file is there, otherwise this test doesn't work as intended
self.assertTrue(os.path.exists(os.path.join(test_modules_path, 'bzip2', '.1.0.6.lua')))
self.assertFalse(os.path.exists(os.path.join(test_modules_path, 'bzip2', '.1.0.6')))
Expand All @@ -155,6 +155,27 @@ def test_exists(self):
self.assertEqual(self.modtool.exist(mod_names), [True, False, True, False, True, True, True])
self.assertEqual(self.modtool.exist(mod_names, skip_avail=True), [True, False, True, False, True, True, True])

# verify whether checking for existence of a module wrapper works
self.modtool.unuse(test_modules_path)
self.modtool.use(self.test_prefix)

write_file(os.path.join(self.test_prefix, 'Java', '1.8.0_181'), '#%Module')
write_file(os.path.join(self.test_prefix, 'Java', '.modulerc'), '#%Module\nmodule-version Java/1.8.0_181 1.8')

expected = ['Java/1.8', 'Java/1.8.0_181']
self.assertEqual(sorted(self.modtool.available()), expected)
self.assertEqual(self.modtool.exist(expected), [True, True])

reset_module_caches()

# what if we're in an HMNS setting...
mkdir(os.path.join(self.test_prefix, 'Core'))
shutil.move(os.path.join(self.test_prefix, 'Java'), 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']), [True])

def test_load(self):
""" test if we load one module it is in the loaded_modules """
self.init_testmods()
Expand Down

0 comments on commit dc8d1f5

Please sign in to comment.