@@ -1328,6 +1328,29 @@ class EnvironmentModules(EnvironmentModulesTcl):
13281328 MAX_VERSION = None
13291329 VERSION_REGEXP = r'^Modules\s+Release\s+(?P<version>\d\S*)\s'
13301330
1331+ def __init__ (self , * args , ** kwargs ):
1332+ """Constructor, set Environment Modules-specific class variable values."""
1333+ # ensure in-depth modulepath search (MODULES_AVAIL_INDEPTH has been introduced in v4.3)
1334+ setvar ('MODULES_AVAIL_INDEPTH' , '1' , verbose = False )
1335+ # match against module name start (MODULES_SEARCH_MATCH has been introduced in v4.3)
1336+ setvar ('MODULES_SEARCH_MATCH' , 'starts_with' , verbose = False )
1337+ # ensure no debug message (MODULES_VERBOSITY has been introduced in v4.3)
1338+ setvar ('MODULES_VERBOSITY' , 'normal' , verbose = False )
1339+ # make module search case sensitive (search is case insensitive by default since v5.0)
1340+ setvar ('MODULES_ICASE' , 'never' , verbose = False )
1341+ # disable extended default (introduced in v4.4 and enabled by default in v5.0)
1342+ setvar ('MODULES_EXTENDED_DEFAULT' , '0' , verbose = False )
1343+ # hard disable output redirection, output messages are expected on stderr
1344+ setvar ('MODULES_REDIRECT_OUTPUT' , '0' , verbose = False )
1345+ # make sure modulefile cache is ignored (cache mechanism supported since v5.3)
1346+ setvar ('MODULES_IGNORE_CACHE' , '1' , verbose = False )
1347+ # ensure only module names are returned on avail (MODULES_AVAIL_TERSE_OUTPUT added in v4.7)
1348+ setvar ('MODULES_AVAIL_TERSE_OUTPUT' , '' , verbose = False )
1349+ # ensure only module names are returned on list (MODULES_LIST_TERSE_OUTPUT added in v4.7)
1350+ setvar ('MODULES_LIST_TERSE_OUTPUT' , '' , verbose = False )
1351+
1352+ super (EnvironmentModules , self ).__init__ (* args , ** kwargs )
1353+
13311354 def check_module_function (self , allow_mismatch = False , regex = None ):
13321355 """Check whether selected module tool matches 'module' function definition."""
13331356 # Modules 5.1.0+: module command is called from _module_raw shell function
@@ -1360,6 +1383,27 @@ def check_module_output(self, cmd, stdout, stderr):
13601383 else :
13611384 self .log .debug ("No errors detected when running module command '%s'" , cmd )
13621385
1386+ def get_setenv_value_from_modulefile (self , mod_name , var_name ):
1387+ """
1388+ Get value for specific 'setenv' statement from module file for the specified module.
1389+
1390+ :param mod_name: module name
1391+ :param var_name: name of the variable being set for which value should be returned
1392+ """
1393+ # Tcl-based module tools produce "module show" output with setenv statements like:
1394+ # "setenv GCC_PATH /opt/gcc/8.3.0"
1395+ # "setenv VAR {some text}
1396+ # - line starts with 'setenv'
1397+ # - whitespace (spaces & tabs) around variable name
1398+ # - curly braces around value if it contain spaces
1399+ value = super (EnvironmentModules , self ).get_setenv_value_from_modulefile (mod_name = mod_name ,
1400+ var_name = var_name )
1401+
1402+ if value :
1403+ value = value .strip ('{}' )
1404+
1405+ return value
1406+
13631407
13641408class Lmod (ModulesTool ):
13651409 """Interface to Lmod."""
0 commit comments