Skip to content

Commit 19decf0

Browse files
authored
Merge pull request #4436 from smoors/modextrapaths_append
add support for appending to path environment variables via `modextrapaths_append` (and add corresponding `allow_append_abs_path`)
2 parents 04a029f + 58d67db commit 19decf0

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

easybuild/framework/easyblock.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,14 @@ def make_module_extra(self, altroot=None, altversion=None):
14211421
value, type(value))
14221422
lines.append(self.module_generator.prepend_paths(key, value, allow_abs=self.cfg['allow_prepend_abs_path']))
14231423

1424+
for (key, value) in self.cfg['modextrapaths_append'].items():
1425+
if isinstance(value, string_type):
1426+
value = [value]
1427+
elif not isinstance(value, (tuple, list)):
1428+
raise EasyBuildError("modextrapaths_append dict value %s (type: %s) is not a list or tuple",
1429+
value, type(value))
1430+
lines.append(self.module_generator.append_paths(key, value, allow_abs=self.cfg['allow_append_abs_path']))
1431+
14241432
modloadmsg = self.cfg['modloadmsg']
14251433
if modloadmsg:
14261434
# add trailing newline to prevent that shell prompt is 'glued' to module load message

easybuild/framework/easyconfig/default.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@
189189
'exts_list': [[], 'List with extensions added to the base installation', EXTENSIONS],
190190

191191
# MODULES easyconfig parameters
192+
'allow_append_abs_path': [False, "Allow specifying absolute paths to append in modextrapaths_append", MODULES],
192193
'allow_prepend_abs_path': [False, "Allow specifying absolute paths to prepend in modextrapaths", MODULES],
193194
'include_modpath_extensions': [True, "Include $MODULEPATH extensions specified by module naming scheme.", MODULES],
194195
'modaliases': [{}, "Aliases to be defined in module file", MODULES],
195196
'modextrapaths': [{}, "Extra paths to be prepended in module file", MODULES],
197+
'modextrapaths_append': [{}, "Extra paths to be appended in module file", MODULES],
196198
'modextravars': [{}, "Extra environment variables to be added to module file", MODULES],
197199
'modloadmsg': [{}, "Message that should be printed when generated module is loaded", MODULES],
198200
'modunloadmsg': [{}, "Message that should be printed when generated module is unloaded", MODULES],

easybuild/framework/easyconfig/format/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
]
7474
LAST_PARAMS = ['exts_default_options', 'exts_list',
7575
'sanity_check_paths', 'sanity_check_commands',
76-
'modextrapaths', 'modextravars',
76+
'modextrapaths', 'modextrapaths_append', 'modextravars',
7777
'moduleclass']
7878

7979
SANITY_CHECK_PATHS_DIRS = 'dirs'

test/framework/easyblock.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ def test_make_module_extra(self):
645645

646646
# also check how absolute paths specified in modexself.contents = '\n'.join([
647647
self.contents += "\nmodextrapaths = {'TEST_PATH_VAR': ['foo', '/test/absolute/path', 'bar']}"
648+
self.contents += "\nmodextrapaths_append = {'TEST_PATH_VAR_APPEND': ['foo', '/test/absolute/path', 'bar']}"
648649
self.writeEC()
649650
ec = EasyConfig(self.eb_file)
650651
eb = EasyBlock(ec)
@@ -657,6 +658,7 @@ def test_make_module_extra(self):
657658

658659
# allow use of absolute paths, and verify contents of module
659660
self.contents += "\nallow_prepend_abs_path = True"
661+
self.contents += "\nallow_append_abs_path = True"
660662
self.writeEC()
661663
ec = EasyConfig(self.eb_file)
662664
eb = EasyBlock(ec)
@@ -675,6 +677,9 @@ def test_make_module_extra(self):
675677
r"^prepend[-_]path.*TEST_PATH_VAR.*root.*foo",
676678
r"^prepend[-_]path.*TEST_PATH_VAR.*/test/absolute/path",
677679
r"^prepend[-_]path.*TEST_PATH_VAR.*root.*bar",
680+
r"^append[-_]path.*TEST_PATH_VAR_APPEND.*root.*foo",
681+
r"^append[-_]path.*TEST_PATH_VAR_APPEND.*/test/absolute/path",
682+
r"^append[-_]path.*TEST_PATH_VAR_APPEND.*root.*bar",
678683
]
679684
for pattern in patterns:
680685
self.assertTrue(re.search(pattern, txt, re.M), "Pattern '%s' found in: %s" % (pattern, txt))
@@ -1173,6 +1178,7 @@ def test_make_module_step(self):
11731178
'PATH': ('xbin', 'pibin'),
11741179
'CPATH': 'pi/include',
11751180
}
1181+
modextrapaths_append = {'APPEND_PATH': 'append_path'}
11761182
self.contents = '\n'.join([
11771183
'easyblock = "ConfigureMake"',
11781184
'name = "%s"' % name,
@@ -1186,6 +1192,7 @@ def test_make_module_step(self):
11861192
"hiddendependencies = [('test', '1.2.3'), ('OpenMPI', '2.1.2-GCC-6.4.0-2.28')]",
11871193
"modextravars = %s" % str(modextravars),
11881194
"modextrapaths = %s" % str(modextrapaths),
1195+
"modextrapaths_append = %s" % str(modextrapaths_append),
11891196
])
11901197

11911198
# test if module is generated correctly
@@ -1256,6 +1263,18 @@ def test_make_module_step(self):
12561263
num_prepends = len(regex.findall(txt))
12571264
self.assertEqual(num_prepends, 1, "Expected exactly 1 %s command in %s" % (regex.pattern, txt))
12581265

1266+
for (key, vals) in modextrapaths_append.items():
1267+
if isinstance(vals, string_type):
1268+
vals = [vals]
1269+
for val in vals:
1270+
if get_module_syntax() == 'Tcl':
1271+
regex = re.compile(r'^append-path\s+%s\s+\$root/%s$' % (key, val), re.M)
1272+
elif get_module_syntax() == 'Lua':
1273+
regex = re.compile(r'^append_path\("%s", pathJoin\(root, "%s"\)\)$' % (key, val), re.M)
1274+
else:
1275+
self.fail("Unknown module syntax: %s" % get_module_syntax())
1276+
self.assertTrue(regex.search(txt), "Pattern %s found in %s" % (regex.pattern, txt))
1277+
12591278
for (name, ver) in [('GCC', '6.4.0-2.28')]:
12601279
if get_module_syntax() == 'Tcl':
12611280
regex = re.compile(r'^\s*module load %s\s*$' % os.path.join(name, ver), re.M)

test/framework/easyconfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ def test_templating_constants(self):
11511151
'R: %%(rver)s, %%(rmajver)s, %%(rminver)s, %%(rshortver)s',
11521152
]),
11531153
'modextrapaths = {"PI_MOD_NAME": "%%(module_name)s"}',
1154+
'modextrapaths_append = {"PATH_APPEND": "appended_path"}',
11541155
'license_file = HOME + "/licenses/PI/license.txt"',
11551156
"github_account = 'easybuilders'",
11561157
]) % inp
@@ -1191,6 +1192,7 @@ def test_templating_constants(self):
11911192
self.assertEqual(ec['modloadmsg'], expected)
11921193
self.assertEqual(ec['modunloadmsg'], expected)
11931194
self.assertEqual(ec['modextrapaths'], {'PI_MOD_NAME': 'PI/3.04-Python-2.7.10'})
1195+
self.assertEqual(ec['modextrapaths_append'], {'PATH_APPEND': 'appended_path'})
11941196
self.assertEqual(ec['license_file'], os.path.join(os.environ['HOME'], 'licenses', 'PI', 'license.txt'))
11951197

11961198
# test the escaping insanity here (ie all the crap we allow in easyconfigs)

test/framework/toy_build.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def test_toy_tweaked(self):
285285
ec_extra = '\n'.join([
286286
"versionsuffix = '-tweaked'",
287287
"modextrapaths = {'SOMEPATH': ['foo/bar', 'baz', '']}",
288+
"modextrapaths_append = {'SOMEPATH_APPEND': ['qux/fred', 'thud', '']}",
288289
"modextravars = {'FOO': 'bar'}",
289290
"modloadmsg = '%s'" % modloadmsg,
290291
"modtclfooter = 'puts stderr \"oh hai!\"'", # ignored when module syntax is Lua
@@ -319,13 +320,21 @@ def test_toy_tweaked(self):
319320
self.assertTrue(re.search(r'^prepend-path\s*SOMEPATH\s*\$root/foo/bar$', toy_module_txt, re.M))
320321
self.assertTrue(re.search(r'^prepend-path\s*SOMEPATH\s*\$root/baz$', toy_module_txt, re.M))
321322
self.assertTrue(re.search(r'^prepend-path\s*SOMEPATH\s*\$root$', toy_module_txt, re.M))
323+
self.assertTrue(re.search(r'^append-path\s*SOMEPATH_APPEND\s*\$root/qux/fred$', toy_module_txt, re.M))
324+
self.assertTrue(re.search(r'^append-path\s*SOMEPATH_APPEND\s*\$root/thud$', toy_module_txt, re.M))
325+
self.assertTrue(re.search(r'^append-path\s*SOMEPATH_APPEND\s*\$root$', toy_module_txt, re.M))
322326
mod_load_msg = r'module-info mode load.*\n\s*puts stderr\s*.*%s$' % modloadmsg_regex_tcl
323327
self.assertTrue(re.search(mod_load_msg, toy_module_txt, re.M))
324328
self.assertTrue(re.search(r'^puts stderr "oh hai!"$', toy_module_txt, re.M))
325329
elif get_module_syntax() == 'Lua':
326330
self.assertTrue(re.search(r'^setenv\("FOO", "bar"\)', toy_module_txt, re.M))
327331
pattern = r'^prepend_path\("SOMEPATH", pathJoin\(root, "foo/bar"\)\)$'
328332
self.assertTrue(re.search(pattern, toy_module_txt, re.M))
333+
pattern = r'^append_path\("SOMEPATH_APPEND", pathJoin\(root, "qux/fred"\)\)$'
334+
self.assertTrue(re.search(pattern, toy_module_txt, re.M))
335+
pattern = r'^append_path\("SOMEPATH_APPEND", pathJoin\(root, "thud"\)\)$'
336+
self.assertTrue(re.search(pattern, toy_module_txt, re.M))
337+
self.assertTrue(re.search(r'^append_path\("SOMEPATH_APPEND", root\)$', toy_module_txt, re.M))
329338
self.assertTrue(re.search(r'^prepend_path\("SOMEPATH", pathJoin\(root, "baz"\)\)$', toy_module_txt, re.M))
330339
self.assertTrue(re.search(r'^prepend_path\("SOMEPATH", root\)$', toy_module_txt, re.M))
331340
mod_load_msg = r'^if mode\(\) == "load" then\n\s*io.stderr:write\(%s\)$' % modloadmsg_regex_lua
@@ -1514,6 +1523,9 @@ def test_toy_module_fulltxt(self):
15141523
r'prepend_path\("SOMEPATH", pathJoin\(root, "foo/bar"\)\)',
15151524
r'prepend_path\("SOMEPATH", pathJoin\(root, "baz"\)\)',
15161525
r'prepend_path\("SOMEPATH", root\)',
1526+
r'append_path\("SOMEPATH_APPEND", pathJoin\(root, "qux/fred"\)\)',
1527+
r'append_path\("SOMEPATH_APPEND", pathJoin\(root, "thud"\)\)',
1528+
r'append_path\("SOMEPATH_APPEND", root\)',
15171529
r'',
15181530
r'if mode\(\) == "load" then',
15191531
] + modloadmsg_lua + [
@@ -1552,6 +1564,9 @@ def test_toy_module_fulltxt(self):
15521564
r'prepend-path SOMEPATH \$root/foo/bar',
15531565
r'prepend-path SOMEPATH \$root/baz',
15541566
r'prepend-path SOMEPATH \$root',
1567+
r'append-path SOMEPATH_APPEND \$root/qux/fred',
1568+
r'append-path SOMEPATH_APPEND \$root/thud',
1569+
r'append-path SOMEPATH_APPEND \$root',
15551570
r'',
15561571
r'if { \[ module-info mode load \] } {',
15571572
] + modloadmsg_tcl + [

0 commit comments

Comments
 (0)