@@ -430,19 +430,26 @@ def det_installdir(self, modfile):
430430
431431 return res
432432
433- def unpack_setenv_value (self , env_var_name , env_var_val ):
433+ def unpack_setenv_value (self , * args , ** kwargs ):
434+ """
435+ """
436+ self .log .deprecated ("..." , '6.0' )
437+ value , use_pushenv , _ = self ._unpack_setenv_value (* args , ** kwargs )
438+ return value , use_pushenv
439+
440+ def _unpack_setenv_value (self , env_var_name , env_var_val ):
434441 """
435442 Unpack value that specifies how to define an environment variable with specified name.
436443 """
437444 use_pushenv = self .DEFAULT_MODEXTRAVARS_PUSHENV
438- shell_vars = self .DEFAULT_MODEXTRAVARS_SHELL_VARS
445+ resolve_shell_vars = self .DEFAULT_MODEXTRAVARS_SHELL_VARS
439446
440447 # value may be specified as a string, or as a dict for special cases
441448 if isinstance (env_var_val , str ):
442449 value = env_var_val
443450 elif isinstance (env_var_val , dict ):
444451 use_pushenv = env_var_val .get ('pushenv' , self .DEFAULT_MODEXTRAVARS_PUSHENV )
445- shell_vars = env_var_val .get ('shell_vars' , self .DEFAULT_MODEXTRAVARS_SHELL_VARS )
452+ resolve_shell_vars = env_var_val .get ('shell_vars' , self .DEFAULT_MODEXTRAVARS_SHELL_VARS )
446453 try :
447454 value = env_var_val ['value' ]
448455 except KeyError as err :
@@ -452,7 +459,7 @@ def unpack_setenv_value(self, env_var_name, env_var_val):
452459 raise EasyBuildError ("Incorrect value type for setting $%s environment variable (%s): %s" ,
453460 env_var_name , type (env_var_val ), env_var_val )
454461
455- return value , use_pushenv , shell_vars
462+ return value , use_pushenv , resolve_shell_vars
456463
457464 # From this point on just not implemented methods
458465
@@ -1065,12 +1072,12 @@ def set_environment(self, key, value, relpath=False):
10651072 self .log .info ("Not including statement to define environment variable $%s, as specified" , key )
10661073 return ''
10671074
1068- set_value , use_pushenv , shell_vars = self .unpack_setenv_value (key , value )
1075+ set_value , use_pushenv , resolve_shell_vars = self ._unpack_setenv_value (key , value )
10691076
10701077 if relpath :
10711078 set_value = os .path .join ('$root' , set_value ) if set_value else '$root'
10721079
1073- if shell_vars :
1080+ if resolve_shell_vars :
10741081 set_value = self .REGEX_SHELL_VAR .sub (r'$::env(\1)' , set_value )
10751082
10761083 # quotes are needed, to ensure smooth working of EBDEVEL* modulefiles
@@ -1161,7 +1168,8 @@ class ModuleGeneratorLua(ModuleGenerator):
11611168 LOAD_TEMPLATE_DEPENDS_ON = 'depends_on("%(mod_name)s")'
11621169 IS_LOADED_TEMPLATE = 'isloaded("%s")'
11631170
1164- PATH_JOIN_TEMPLATE = 'pathJoin(root, "%s")' # TODO: remove after 6.0, replaced by _path_join_cmd()
1171+ OS_GETENV_TEMPLATE = r'os.getenv("%s")'
1172+ PATH_JOIN_TEMPLATE = 'pathJoin(root, "%s")'
11651173 UPDATE_PATH_TEMPLATE = '%s_path("%s", %s)'
11661174 UPDATE_PATH_TEMPLATE_DELIM = '%s_path("%s", %s, "%s")'
11671175
@@ -1186,9 +1194,10 @@ def _path_join_cmd(path):
11861194 path_components .insert (0 , path_root )
11871195
11881196 if len (path_components ) > 1 :
1189- return f'pathJoin({ ", " .join (path_components )} )'
1197+ return 'pathJoin(' + ', ' .join (path_components ) + ')'
1198+
11901199 # no need for a pathJoin for single component paths
1191- return os . path . join ( * path_components )
1200+ return path_components [ 0 ]
11921201
11931202 def check_version (self , minimal_version_maj , minimal_version_min , minimal_version_patch = '0' ):
11941203 """
@@ -1315,10 +1324,9 @@ def getenv_cmd(self, envvar, default=None):
13151324 """
13161325 Return module-syntax specific code to get value of specific environment variable.
13171326 """
1318- if default is None :
1319- cmd = 'os.getenv("%s")' % envvar
1320- else :
1321- cmd = 'os.getenv("%s") or "%s"' % (envvar , default )
1327+ cmd = self .OS_GETENV_TEMPLATE % envvar
1328+ if default is not None :
1329+ cmd += f' or "{ default } "'
13221330 return cmd
13231331
13241332 def load_module (self , mod_name , recursive_unload = None , depends_on = None , unload_modules = None , multi_dep_mods = None ):
@@ -1536,18 +1544,23 @@ def set_environment(self, key, value, relpath=False):
15361544 self .log .info ("Not including statement to define environment variable $%s, as specified" , key )
15371545 return ''
15381546
1539- set_value , use_pushenv , shell_vars = self .unpack_setenv_value (key , value )
1547+ set_value , use_pushenv , resolve_shell_vars = self ._unpack_setenv_value (key , value )
15401548
15411549 if relpath :
15421550 set_value = self ._path_join_cmd (set_value )
1543- if shell_vars :
1544- set_value = self .REGEX_QUOTE_SHELL_VAR .sub (r'os.getenv("\1")' , set_value )
1551+ if resolve_shell_vars :
1552+ # replace quoted substring with env var with os.getenv statement
1553+ # example: pathJoin(root, "$HOME") -> pathJoin(root, os.getenv("HOME"))
1554+ set_value = self .REGEX_QUOTE_SHELL_VAR .sub (self .OS_GETENV_TEMPLATE % r"\1" , set_value )
15451555 else :
1546- if shell_vars :
1547- set_value = self .REGEX_SHELL_VAR .sub (rf'{ self .CONCAT_STR } os.getenv("\1"){ self .CONCAT_STR } ' , set_value )
1556+ if resolve_shell_vars :
1557+ # replace env var with os.getenv statement
1558+ # example: $HOME -> os.getenv("HOME")
1559+ concat_getenv = self .CONCAT_STR + self .OS_GETENV_TEMPLATE % r"\1" + self .CONCAT_STR
1560+ set_value = self .REGEX_SHELL_VAR .sub (concat_getenv , set_value )
15481561 set_value = self .CONCAT_STR .join ([
1549- # quote any substrings that are not lua commands
1550- quote_str ( x ) if not x .startswith ('os.' ) else x
1562+ # quote any substrings that are not a os.getenv Lua statement
1563+ x if x .startswith (self . OS_GETENV_TEMPLATE [: 10 ] ) else quote_str ( x )
15511564 for x in set_value .strip (self .CONCAT_STR ).split (self .CONCAT_STR )
15521565 ])
15531566
0 commit comments