From dc8d1f53e07e1bb7241376de96f2445c757f5b75 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Tue, 2 Oct 2018 20:56:57 +0200 Subject: [PATCH] also check for module wrappers in 'ModulesTool.exist' method (WIP) --- easybuild/tools/modules.py | 17 +++++++++++++++-- test/framework/modules.py | 23 ++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/easybuild/tools/modules.py b/easybuild/tools/modules.py index a9291c5bfc..585b5eb5dc 100644 --- a/easybuild/tools/modules.py +++ b/easybuild/tools/modules.py @@ -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: @@ -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 diff --git a/test/framework/modules.py b/test/framework/modules.py index d8943faca4..c2489ed49a 100644 --- a/test/framework/modules.py +++ b/test/framework/modules.py @@ -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'))) @@ -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()