Skip to content

Commit 9c0de5d

Browse files
committed
Add support for non-path variables in module_load_environment
Useful for simple values. Using existing logic. If the value is a list elements are joined using the delimiter.
1 parent 2e7a04d commit 9c0de5d

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

easybuild/framework/easyblock.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,14 +1738,6 @@ def make_module_req(self):
17381738
if envar_val.is_path
17391739
}
17401740
self.log.debug(f"Tentative module environment requirements before path expansion: {env_var_requirements}")
1741-
# TODO: handle non-path variables in make_module_extra
1742-
# in the meantime, just report if any is found
1743-
non_path_envars = set(self.module_load_environment) - set(env_var_requirements)
1744-
if non_path_envars:
1745-
self.log.warning(
1746-
f"Non-path variables found in module load environment: {non_path_envars}."
1747-
"This is not yet supported by this version of EasyBuild."
1748-
)
17491741

17501742
mod_lines = ['\n']
17511743

@@ -1770,6 +1762,10 @@ def make_module_req(self):
17701762
delim=search_paths.delimiter)
17711763
mod_lines.append(extra_mod_lines)
17721764

1765+
for env_var, value in sorted(self.module_load_environment.items()):
1766+
if env_var not in env_var_requirements:
1767+
mod_lines.append(self.module_generator.set_environment(env_var, value.delimiter.join(value.contents)))
1768+
17731769
if self.dry_run:
17741770
self.dry_run_msg('')
17751771

test/framework/easyblock.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ def test_make_module_req(self):
650650
r'prepend_path\("PATH", pathJoin\(root, "%s"\)\)\n' % sub_path_path, re.M))
651651

652652
# Module load environement may contain non-path variables
653-
# TODO: remove whenever this is properly supported, in the meantime check warning
654653
eb.module_load_environment.NONPATH = {'contents': 'non_path', 'var_type': "STRING"}
655654
eb.module_load_environment.PATH = ['bin']
656655
with self.mocked_stdout_stderr():
@@ -659,16 +658,16 @@ def test_make_module_req(self):
659658
self.assertEqual(list(eb.module_load_environment), ['PATH', 'LD_LIBRARY_PATH', 'NONPATH'])
660659

661660
if get_module_syntax() == 'Tcl':
662-
self.assertTrue(re.match(r"^\nprepend-path\s+PATH\s+\$root/bin\n$", txt, re.M))
663-
self.assertFalse(re.match(r"^\nprepend-path\s+NONPATH\s+\$root/non_path\n$", txt, re.M))
661+
self.assertRegex(txt, re.compile(r"^\nprepend-path\s+PATH\s+\$root/bin\n", re.M))
662+
self.assertRegex(txt, re.compile(r'^setenv\s+NONPATH\s+"non_path"\s*$', re.M))
664663
elif get_module_syntax() == 'Lua':
665-
self.assertTrue(re.match(r'^\nprepend_path\("PATH", pathJoin\(root, "bin"\)\)\n$', txt, re.M))
666-
self.assertFalse(re.match(r'^\nprepend_path\("NONPATH", pathJoin\(root, "non_path"\)\)\n$', txt, re.M))
664+
self.assertRegex(txt, re.compile(r'^prepend_path\("PATH", pathJoin\(root, "bin"\)\)$', re.M))
665+
self.assertRegex(txt, re.compile(r'^setenv\("NONPATH", "non_path"\)$', re.M))
667666
else:
668667
self.fail("Unknown module syntax: %s" % get_module_syntax())
669668

670669
logtxt = read_file(eb.logfile)
671-
self.assertRegex(logtxt, r"WARNING Non-path variables found in module load env.*NONPATH")
670+
self.assertNotRegex(logtxt, r"WARNING Non-path variables found in module load env.*NONPATH")
672671

673672
eb.module_load_environment.remove('NONPATH')
674673

0 commit comments

Comments
 (0)