@@ -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
806836class 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.
0 commit comments