Skip to content

Commit 9f82a1b

Browse files
committed
Avoid use of priority in prepend_module_path
1 parent 380dc5b commit 9f82a1b

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

easybuild/framework/easyblock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ def load_fake_module(self, purge=False, extra_modules=None):
15551555
fake_mod_path = self.make_module_step(fake=True)
15561556

15571557
# load fake module
1558-
self.modules_tool.prepend_module_path(os.path.join(fake_mod_path, self.mod_subdir), priority=10000)
1558+
self.modules_tool.prepend_module_path(os.path.join(fake_mod_path, self.mod_subdir))
15591559
self.load_module(purge=purge, extra_modules=extra_modules)
15601560

15611561
return (fake_mod_path, env)

easybuild/tools/modules.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class ModulesTool(object):
153153
VERSION_REGEXP = None
154154
# modules tool user cache directory
155155
USER_CACHE_DIR = None
156+
# Priority used to put module paths at the front when priorities are otherwise used
157+
HIGH_PRIORITY = 10000
156158

157159
def __init__(self, mod_paths=None, testing=False):
158160
"""
@@ -1473,7 +1475,17 @@ def prepend_module_path(self, path, set_mod_paths=True, priority=None):
14731475
# Lmod pushes a path to the front on 'module use', no need for (costly) 'module unuse'
14741476
modulepath = curr_module_paths()
14751477
if not modulepath or os.path.realpath(modulepath[0]) != os.path.realpath(path):
1478+
# If no explicit priority is set, but priorities are already in use we need to use a high
1479+
# priority to make sure the path (very likely) ends up at the front
1480+
if priority is None and os.environ.get('__LMOD_Priority_MODULEPATH'):
1481+
priority = self.HIGH_PRIORITY
14761482
self.use(path, priority=priority)
1483+
modulepath = curr_module_paths(clean=False)
1484+
path_idx = modulepath.index(path)
1485+
if path_idx != 0:
1486+
self.log.warn("Path '%s' could not be prepended to $MODULEPATH. The following paths have a higher "
1487+
"priority: %s'",
1488+
path, "; ".join(modulepath[:path_idx]))
14771489
if set_mod_paths:
14781490
self.set_mod_paths()
14791491

test/framework/modules.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,14 @@ def test_prepend_module_path(self):
620620
if isinstance(self.modtool, Lmod):
621621
self.modtool.prepend_module_path(test_path_1)
622622
modulepath = curr_module_paths()
623-
self.assertEqual(test_path_0, modulepath[0])
623+
self.assertEqual(test_path_1, modulepath[0])
624+
self.assertEqual(test_path_0, modulepath[1])
625+
test_path_2 = tempfile.mkdtemp(suffix='path_2')
626+
self.modtool.prepend_module_path(test_path_2)
627+
modulepath = curr_module_paths()
628+
self.assertEqual(test_path_2, modulepath[0])
624629
self.assertEqual(test_path_1, modulepath[1])
630+
self.assertEqual(test_path_0, modulepath[2])
625631

626632
def test_ld_library_path(self):
627633
"""Make sure LD_LIBRARY_PATH is what it should be when loaded multiple modules."""

0 commit comments

Comments
 (0)