@@ -361,12 +361,14 @@ def set_mod_paths(self, mod_paths=None):
361361
362362 self .log .debug ("$MODULEPATH after set_mod_paths: %s" % os .environ .get ('MODULEPATH' , '' ))
363363
364- def use (self , path , priority = None ):
364+ def use (self , path , priority = None , force_module_command = False ):
365365 """
366366 Add path to $MODULEPATH via 'module use'.
367367
368368 :param path: path to add to $MODULEPATH
369369 :param priority: priority for this path in $MODULEPATH (Lmod-specific)
370+ :param force_module_command: If False running the module command may be skipped which is faster
371+ but does not reload modules
370372 """
371373 if priority :
372374 self .log .info ("Ignoring specified priority '%s' when running 'module use %s' (Lmod-specific)" ,
@@ -380,8 +382,14 @@ def use(self, path, priority=None):
380382 mkdir (path , parents = True )
381383 self .run_module (['use' , path ])
382384
383- def unuse (self , path ):
384- """Remove module path via 'module unuse'."""
385+ def unuse (self , path , force_module_command = False ):
386+ """
387+ Remove a module path (usually) via 'module unuse'.
388+
389+ :param path: path to remove from $MODULEPATH
390+ :param force_module_command: If False running the module command may be skipped which is faster
391+ but does not reload modules
392+ """
385393 self .run_module (['unuse' , path ])
386394
387395 def add_module_path (self , path , set_mod_paths = True ):
@@ -1473,12 +1481,14 @@ def _has_module_paths_with_priority(self):
14731481 # See https://github.com/TACC/Lmod/issues/509
14741482 return bool (os .environ .get ('__LMOD_Priority_MODULEPATH' ))
14751483
1476- def use (self , path , priority = None ):
1484+ def use (self , path , priority = None , force_module_command = False ):
14771485 """
14781486 Add path to $MODULEPATH via 'module use'.
14791487
14801488 :param path: path to add to $MODULEPATH
14811489 :param priority: priority for this path in $MODULEPATH (Lmod-specific)
1490+ :param force_module_command: If False running the module command may be skipped which is faster
1491+ but does not reload modules
14821492 """
14831493 if not path :
14841494 raise EasyBuildError ("Cannot add empty path to $MODULEPATH" )
@@ -1492,17 +1502,26 @@ def use(self, path, priority=None):
14921502 else :
14931503 # LMod allows modifying MODULEPATH directly. So do that to avoid the costly module use
14941504 # unless priorities are in use already
1495- if self ._has_module_paths_with_priority ():
1505+ if force_module_command or self ._has_module_paths_with_priority ():
14961506 self .run_module (['use' , path ])
14971507 else :
14981508 path = normalize_path (path )
14991509 self ._set_module_path ([path ] + [p for p in curr_module_paths (clean = False ) if normalize_path (p ) != path ])
15001510
1501- def unuse (self , path ):
1502- """Remove a module path"""
1503- # We can simply remove the path from MODULEPATH to avoid the costly module call
1504- path = normalize_path (path )
1505- self ._set_module_path (p for p in curr_module_paths (clean = False ) if normalize_path (p ) != path )
1511+ def unuse (self , path , force_module_command = False ):
1512+ """
1513+ Remove a module path
1514+
1515+ :param path: path to remove from $MODULEPATH
1516+ :param force_module_command: If False running the module command may be skipped which is faster
1517+ but does not reload modules
1518+ """
1519+ if force_module_command :
1520+ super (Lmod , self ).unuse (path )
1521+ else :
1522+ # We can simply remove the path from MODULEPATH to avoid the costly module call
1523+ path = normalize_path (path )
1524+ self ._set_module_path (p for p in curr_module_paths (clean = False ) if normalize_path (p ) != path )
15061525
15071526 def prepend_module_path (self , path , set_mod_paths = True , priority = None ):
15081527 """
0 commit comments