Skip to content

Commit 006186f

Browse files
committed
Unuse the actual (non-normalized) path from $MODULEPATH
1 parent 4384a98 commit 006186f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

easybuild/tools/modules.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,13 @@ def remove_module_path(self, path, set_mod_paths=True):
397397
"""
398398
# remove module path via 'module unuse' and make sure self.mod_paths is synced
399399
path = normalize_path(path)
400-
if path in curr_module_paths(normalize=True):
401-
self.unuse(path)
400+
try:
401+
# Unuse the path that is actually present in the environment
402+
module_path = next(p for p in curr_module_paths() if normalize_path(p) == path)
403+
except StopIteration:
404+
pass
405+
else:
406+
self.unuse(module_path)
402407

403408
if set_mod_paths:
404409
self.set_mod_paths()
@@ -1295,8 +1300,13 @@ def remove_module_path(self, path, set_mod_paths=True):
12951300
# modulecmd.tcl keeps track of how often a path was added via 'module use',
12961301
# so we need to check to make sure it's really removed
12971302
path = normalize_path(path)
1298-
while path in curr_module_paths(normalize=True):
1299-
self.unuse(path)
1303+
while True:
1304+
try:
1305+
# Unuse the path that is actually present in the environment
1306+
module_path = next(p for p in curr_module_paths() if normalize_path(p) == path)
1307+
except StopIteration:
1308+
break
1309+
self.unuse(module_path)
13001310
if set_mod_paths:
13011311
self.set_mod_paths()
13021312

@@ -1451,7 +1461,7 @@ def use(self, path, priority=None):
14511461
if cur_mod_path is None:
14521462
new_mod_path = path
14531463
else:
1454-
new_mod_path = [path] + [p for p in cur_mod_path.split(':') if p != path]
1464+
new_mod_path = [path] + [p for p in cur_mod_path.split(':') if normalize_path(p) != path]
14551465
new_mod_path = ':'.join(new_mod_path)
14561466
self.log.debug('Changing MODULEPATH from %s to %s' %
14571467
('<unset>' if cur_mod_path is None else cur_mod_path, new_mod_path))
@@ -1468,7 +1478,7 @@ def unuse(self, path):
14681478
del os.environ['MODULEPATH']
14691479
else:
14701480
path = normalize_path(path)
1471-
new_mod_path = ':'.join(p for p in cur_mod_path.split(':') if p != path)
1481+
new_mod_path = ':'.join(p for p in cur_mod_path.split(':') if normalize_path(p) != path)
14721482
if new_mod_path != cur_mod_path:
14731483
self.log.debug('Changing MODULEPATH from %s to %s' % (cur_mod_path, new_mod_path))
14741484
os.environ['MODULEPATH'] = new_mod_path

0 commit comments

Comments
 (0)