@@ -430,19 +430,26 @@ def det_installdir(self, modfile):
430
430
431
431
return res
432
432
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 ):
434
441
"""
435
442
Unpack value that specifies how to define an environment variable with specified name.
436
443
"""
437
444
use_pushenv = self .DEFAULT_MODEXTRAVARS_PUSHENV
438
- shell_vars = self .DEFAULT_MODEXTRAVARS_SHELL_VARS
445
+ resolve_shell_vars = self .DEFAULT_MODEXTRAVARS_SHELL_VARS
439
446
440
447
# value may be specified as a string, or as a dict for special cases
441
448
if isinstance (env_var_val , str ):
442
449
value = env_var_val
443
450
elif isinstance (env_var_val , dict ):
444
451
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 )
446
453
try :
447
454
value = env_var_val ['value' ]
448
455
except KeyError as err :
@@ -452,7 +459,7 @@ def unpack_setenv_value(self, env_var_name, env_var_val):
452
459
raise EasyBuildError ("Incorrect value type for setting $%s environment variable (%s): %s" ,
453
460
env_var_name , type (env_var_val ), env_var_val )
454
461
455
- return value , use_pushenv , shell_vars
462
+ return value , use_pushenv , resolve_shell_vars
456
463
457
464
# From this point on just not implemented methods
458
465
@@ -1065,12 +1072,12 @@ def set_environment(self, key, value, relpath=False):
1065
1072
self .log .info ("Not including statement to define environment variable $%s, as specified" , key )
1066
1073
return ''
1067
1074
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 )
1069
1076
1070
1077
if relpath :
1071
1078
set_value = os .path .join ('$root' , set_value ) if set_value else '$root'
1072
1079
1073
- if shell_vars :
1080
+ if resolve_shell_vars :
1074
1081
set_value = self .REGEX_SHELL_VAR .sub (r'$::env(\1)' , set_value )
1075
1082
1076
1083
# quotes are needed, to ensure smooth working of EBDEVEL* modulefiles
@@ -1161,7 +1168,8 @@ class ModuleGeneratorLua(ModuleGenerator):
1161
1168
LOAD_TEMPLATE_DEPENDS_ON = 'depends_on("%(mod_name)s")'
1162
1169
IS_LOADED_TEMPLATE = 'isloaded("%s")'
1163
1170
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")'
1165
1173
UPDATE_PATH_TEMPLATE = '%s_path("%s", %s)'
1166
1174
UPDATE_PATH_TEMPLATE_DELIM = '%s_path("%s", %s, "%s")'
1167
1175
@@ -1186,9 +1194,10 @@ def _path_join_cmd(path):
1186
1194
path_components .insert (0 , path_root )
1187
1195
1188
1196
if len (path_components ) > 1 :
1189
- return f'pathJoin({ ", " .join (path_components )} )'
1197
+ return 'pathJoin(' + ', ' .join (path_components ) + ')'
1198
+
1190
1199
# no need for a pathJoin for single component paths
1191
- return os . path . join ( * path_components )
1200
+ return path_components [ 0 ]
1192
1201
1193
1202
def check_version (self , minimal_version_maj , minimal_version_min , minimal_version_patch = '0' ):
1194
1203
"""
@@ -1315,10 +1324,9 @@ def getenv_cmd(self, envvar, default=None):
1315
1324
"""
1316
1325
Return module-syntax specific code to get value of specific environment variable.
1317
1326
"""
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 } "'
1322
1330
return cmd
1323
1331
1324
1332
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):
1536
1544
self .log .info ("Not including statement to define environment variable $%s, as specified" , key )
1537
1545
return ''
1538
1546
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 )
1540
1548
1541
1549
if relpath :
1542
1550
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 )
1545
1555
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 )
1548
1561
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 )
1551
1564
for x in set_value .strip (self .CONCAT_STR ).split (self .CONCAT_STR )
1552
1565
])
1553
1566
0 commit comments