@@ -915,16 +915,19 @@ def load_module(self, mod_paths=None, purge=True):
915915 """
916916 Load module for this software package/version, after purging all currently loaded modules.
917917 """
918+ modtool = modules_tool ()
919+ if mod_paths is not None :
920+ for mod_path in mod_paths :
921+ modtool .prepend_module_path (mod_path )
918922 # self.mod_name might not be set (e.g. during unit tests)
919923 if self .mod_name is not None :
920- m = modules_tool (mod_paths = mod_paths )
921924 # purge all loaded modules if desired
922925 if purge :
923- m .purge ()
926+ modtool .purge ()
924927 # restore original environment
925928 modify_env (os .environ , self .orig_environ )
926- m .check_module_path () # make sure MODULEPATH is set correctly after purging
927- m .load ([self .mod_name ])
929+ modtool .check_module_path () # make sure MODULEPATH is set correctly after purging
930+ modtool .load ([self .mod_name ])
928931 else :
929932 self .log .warning ("Not loading module, since self.mod_name is not set." )
930933
@@ -940,35 +943,29 @@ def load_fake_module(self, purge=False):
940943 fake_mod_path = self .make_module_step (True )
941944
942945 # load fake module
943- mod_paths = [fake_mod_path ]
944- mod_paths .extend (self .orig_modulepath .split (':' ))
945- self .log .debug ("mod_paths: %s" % mod_paths )
946-
947- self .load_module (mod_paths = mod_paths , purge = purge )
946+ modtool = modules_tool ()
947+ modtool .prepend_module_path (fake_mod_path )
948+ self .load_module (purge = purge )
948949
949950 return (fake_mod_path , orig_env )
950951
951952 def clean_up_fake_module (self , fake_mod_data ):
952953 """
953954 Clean up fake module.
954955 """
955-
956956 fake_mod_path , orig_env = fake_mod_data
957-
958957 # unload module and remove temporary module directory
959- if fake_mod_path :
958+ # self.mod_name might not be set (e.g. during unit tests)
959+ if fake_mod_path and self .mod_name is not None :
960960 try :
961- mod_paths = [fake_mod_path ]
962- mod_paths .extend (self .modules_tool .mod_paths )
963- m = modules_tool (mod_paths = mod_paths )
964- # self.mod_name might not be set (e.g. during unit tests)
965- if self .mod_name is not None :
966- m .unload ([self .mod_name ])
967- else :
968- self .log .warning ("Not unloading module, since self.mod_name is not set." )
961+ modtool = modules_tool ()
962+ modtool .unload ([self .mod_name ])
963+ modtool .remove_module_path (fake_mod_path )
969964 rmtree2 (os .path .dirname (fake_mod_path ))
970965 except OSError , err :
971966 self .log .error ("Failed to clean up fake module dir: %s" % err )
967+ elif self .mod_name is None :
968+ self .log .warning ("Not unloading module, since self.mod_name is not set." )
972969
973970 # restore original environment
974971 modify_env (os .environ , orig_env )
0 commit comments