From 25a367e88e6616c5e2b32bd8f8e15ff84d807543 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Wed, 8 Jan 2025 07:08:40 +0100 Subject: [PATCH 1/2] Disable exit code check when running "module show" The "module show" command is used by ModulesTool "exist" method to test the existence of a modulefile. Running "module show" against a non-existing modulefile will make modulecmd.tcl script to produce a non-zero exit code starting Modules v5.5. With this change, the exit code check when running "module show" is disabled. It should not harm the module existence check as it relies on the analysis of the obtained stderr output. Note that Lmod (as of version 8.7.55) does not set a non-zero exit code when running "module show" against a non-existing modulefile when LMOD_QUIET environment variable is set. If this behavior is changed in the future, this commit will also benefit to Lmod. --- easybuild/tools/modules.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easybuild/tools/modules.py b/easybuild/tools/modules.py index 7feba289f3..20b66dc289 100644 --- a/easybuild/tools/modules.py +++ b/easybuild/tools/modules.py @@ -709,7 +709,8 @@ def show(self, mod_name): ans = MODULE_SHOW_CACHE[key] self.log.debug("Found cached result for 'module show %s' with key '%s': %s", mod_name, key, ans) else: - ans = self.run_module('show', mod_name, check_output=False, return_stderr=True) + ans = self.run_module('show', mod_name, check_output=False, return_stderr=True, + check_exit_code=False) MODULE_SHOW_CACHE[key] = ans self.log.debug("Cached result for 'module show %s' with key '%s': %s", mod_name, key, ans) From d257b874be6ff312b2c7b232a891f7a75b8a50fa Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Wed, 8 Jan 2025 07:20:39 +0100 Subject: [PATCH 2/2] EnvironmentModules now correctly set a non-zero exit code Starting Environment Modules v5.5, a non-zero exit code is set by modulecmd.tcl when trying to load a non-existing module. --- test/framework/modules.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/framework/modules.py b/test/framework/modules.py index bdd1e595a0..7efe9001a5 100644 --- a/test/framework/modules.py +++ b/test/framework/modules.py @@ -122,10 +122,12 @@ def test_run_module(self): error_pattern = "Module command '.*thisdoesnotmakesense' failed with exit code [1-9]" self.assertErrorRegex(EasyBuildError, error_pattern, self.modtool.run_module, 'thisdoesnotmakesense') - # we need to use a different error pattern here with Environment Modules, - # because a load of a non-existing module doesnt' trigger a non-zero exit code... - # it will still fail though, just differently - if isinstance(self.modtool, EnvironmentModulesC) or isinstance(self.modtool, EnvironmentModules): + # we need to use a different error pattern here with EnvironmentModulesC and + # EnvironmentModules <5.5, because a load of a non-existing module doesnt' trigger a + # non-zero exit code. it will still fail though, just differently + version = LooseVersion(self.modtool.version) + if (isinstance(self.modtool, EnvironmentModulesC) + or (isinstance(self.modtool, EnvironmentModules) and version < '5.5')): error_pattern = "Unable to locate a modulefile for 'nosuchmodule/1.2.3'" else: error_pattern = "Module command '.*load nosuchmodule/1.2.3' failed with exit code [1-9]"