@@ -1467,6 +1467,12 @@ def _set_module_path(self, new_mod_path):
14671467 else :
14681468 os .environ ['MODULEPATH' ] = new_mod_path
14691469
1470+ def _has_module_paths_with_priority (self ):
1471+ """Return True if there are priorities attached to $MODULEPATH"""
1472+ # We simply check, if the Lmod variable is set and non-empty
1473+ # See https://github.com/TACC/Lmod/issues/509
1474+ return bool (os .environ .get ('__LMOD_Priority_MODULEPATH' ))
1475+
14701476 def use (self , path , priority = None ):
14711477 """
14721478 Add path to $MODULEPATH via 'module use'.
@@ -1486,7 +1492,7 @@ def use(self, path, priority=None):
14861492 else :
14871493 # LMod allows modifying MODULEPATH directly. So do that to avoid the costly module use
14881494 # unless priorities are in use already
1489- if os . environ . get ( '__LMOD_Priority_MODULEPATH' ):
1495+ if self . _has_module_paths_with_priority ( ):
14901496 self .run_module (['use' , path ])
14911497 else :
14921498 path = normalize_path (path )
@@ -1511,7 +1517,7 @@ def prepend_module_path(self, path, set_mod_paths=True, priority=None):
15111517 if not modulepath or os .path .realpath (modulepath [0 ]) != os .path .realpath (path ):
15121518 # If no explicit priority is set, but priorities are already in use we need to use a high
15131519 # priority to make sure the path (very likely) ends up at the front
1514- if priority is None and os . environ . get ( '__LMOD_Priority_MODULEPATH' ):
1520+ if priority is None and self . _has_module_paths_with_priority ( ):
15151521 priority = self .HIGH_PRIORITY
15161522 self .use (path , priority = priority )
15171523 modulepath = curr_module_paths (clean = False )
0 commit comments