Skip to content

Commit 4b35b02

Browse files
author
Vasileios Karakasis
authored
Merge pull request #1656 from teojgo/bugfix/module_collections_cli_usepath
[bugfix] Restore module paths specified in command line when restoring module collections
2 parents 0803cce + 2062d23 commit 4b35b02

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

reframe/core/modules.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ def __init__(self):
744744
(version, self.MIN_VERSION))
745745

746746
self._version = version
747+
self._extra_module_paths = []
747748

748749
def name(self):
749750
return 'tmod4'
@@ -770,6 +771,15 @@ def _execute(self, cmd, *args):
770771
def load_module(self, module):
771772
if module.collection:
772773
self.execute('restore', str(module))
774+
775+
# Here the module search path removal/addition is repeated since
776+
# 'restore' discards previous module path manipulations
777+
for op, mp in self._extra_module_paths:
778+
if op == '+':
779+
super().searchpath_add(mp)
780+
else:
781+
super().searchpath_remove(mp)
782+
773783
return []
774784
else:
775785
return super().load_module(module)
@@ -792,7 +802,15 @@ def conflicted_modules(self, module):
792802

793803
def emit_load_instr(self, module):
794804
if module.collection:
795-
return f'module restore {module}'
805+
cmds = [f'module restore {module}']
806+
807+
# Here we append module searchpath removal/addition commands
808+
# since 'restore' discards previous module path manipulations
809+
for op, mp in self._extra_module_paths:
810+
operation = 'use' if op == '+' else 'unuse'
811+
cmds += [f'module {operation} {mp}']
812+
813+
return '\n'.join(cmds)
796814

797815
return super().emit_load_instr(module)
798816

@@ -802,6 +820,18 @@ def emit_unload_instr(self, module):
802820

803821
return super().emit_unload_instr(module)
804822

823+
def searchpath_add(self, *dirs):
824+
if dirs:
825+
self._extra_module_paths += [('+', mp) for mp in dirs]
826+
827+
super().searchpath_add(*dirs)
828+
829+
def searchpath_remove(self, *dirs):
830+
if dirs:
831+
self._extra_module_paths += [('-', mp) for mp in dirs]
832+
833+
super().searchpath_remove(*dirs)
834+
805835

806836
class LModImpl(TMod4Impl):
807837
'''Module system for Lmod (Tcl/Lua).'''
@@ -836,6 +866,8 @@ def __init__(self):
836866
raise ConfigError('Python is not supported by '
837867
'this Lmod installation')
838868

869+
self._extra_module_paths = []
870+
839871
def name(self):
840872
return 'lmod'
841873

@@ -891,20 +923,6 @@ def conflicted_modules(self, module):
891923

892924
return ret
893925

894-
def load_module(self, module):
895-
if module.collection:
896-
self.execute('restore', str(module))
897-
return []
898-
else:
899-
return super().load_module(module)
900-
901-
def unload_module(self, module):
902-
if module.collection:
903-
# Module collection are not unloaded
904-
return
905-
906-
super().unload_module(module)
907-
908926
def unload_all(self):
909927
# Currently, we don't take any provision for sticky modules in Lmod, so
910928
# we forcefully unload everything.

unittests/test_modules.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55

6-
import abc
76
import os
87
import pytest
98

109
import reframe.core.environments as env
1110
import reframe.core.modules as modules
12-
import reframe.utility as util
13-
import reframe.utility.osext as osext
1411
import unittests.fixtures as fixtures
15-
from reframe.core.exceptions import (ConfigError, EnvironError)
16-
from reframe.core.runtime import runtime
12+
from reframe.core.exceptions import ConfigError, EnvironError
1713

1814

1915
@pytest.fixture(params=['tmod', 'tmod4', 'lmod', 'nomod'])
@@ -130,6 +126,18 @@ def test_module_load_force_collection(modules_system, module_collection):
130126
assert modules_system.is_module_loaded('testmod_foo')
131127

132128

129+
def test_module_load_collection_searchpath(modules_system, tmpdir,
130+
module_collection):
131+
p1 = str(tmpdir.mkdir('path1'))
132+
p2 = str(tmpdir.mkdir('path2'))
133+
modules_system.searchpath_add(p1)
134+
modules_system.searchpath_add(p2)
135+
modules_system.searchpath_remove(p1)
136+
modules_system.load_module(module_collection, collection=True)
137+
assert p1 not in modules_system.searchpath
138+
assert p2 in modules_system.searchpath
139+
140+
133141
def test_module_unload_all(modules_system):
134142
if modules_system.name == 'nomod':
135143
modules_system.unload_all()

0 commit comments

Comments
 (0)