4646from easybuild .tools .config import EBROOT_ENV_VAR_ACTIONS , LOADED_MODULES_ACTIONS
4747from easybuild .tools .config import build_option , get_modules_tool , install_path
4848from easybuild .tools .environment import ORIG_OS_ENVIRON , restore_env , setvar , unset_env_vars
49- from easybuild .tools .filetools import convert_name , mkdir , path_matches , read_file , which , write_file
49+ from easybuild .tools .filetools import convert_name , mkdir , normalize_path , path_matches , read_file , which , write_file
5050from easybuild .tools .module_naming_scheme .mns import DEVEL_MODULE_SUFFIX
5151from easybuild .tools .py2vs3 import subprocess_popen_text
5252from easybuild .tools .run import run_cmd
@@ -381,8 +381,8 @@ def add_module_path(self, path, set_mod_paths=True):
381381 :param path: path to add to $MODULEPATH via 'use'
382382 :param set_mod_paths: (re)set self.mod_paths
383383 """
384- path = path . rstrip ( os . path . sep )
385- if path not in curr_module_paths ():
384+ path = normalize_path ( path )
385+ if path not in curr_module_paths (normalize = True ):
386386 # add module path via 'module use' and make sure self.mod_paths is synced
387387 self .use (path )
388388 if set_mod_paths :
@@ -396,8 +396,8 @@ def remove_module_path(self, path, set_mod_paths=True):
396396 :param set_mod_paths: (re)set self.mod_paths
397397 """
398398 # remove module path via 'module unuse' and make sure self.mod_paths is synced
399- path = path . rstrip ( os . path . sep )
400- if path in curr_module_paths ():
399+ path = normalize_path ( path )
400+ if path in curr_module_paths (normalize = True ):
401401 self .unuse (path )
402402
403403 if set_mod_paths :
@@ -1294,8 +1294,8 @@ def remove_module_path(self, path, set_mod_paths=True):
12941294 # remove module path via 'module use' and make sure self.mod_paths is synced
12951295 # modulecmd.tcl keeps track of how often a path was added via 'module use',
12961296 # so we need to check to make sure it's really removed
1297- path = path . rstrip ( os . path . sep )
1298- while path in curr_module_paths ():
1297+ path = normalize_path ( path )
1298+ while path in curr_module_paths (normalize = True ):
12991299 self .unuse (path )
13001300 if set_mod_paths :
13011301 self .set_mod_paths ()
@@ -1446,7 +1446,7 @@ def use(self, path, priority=None):
14461446 if os .environ .get ('__LMOD_Priority_MODULEPATH' ):
14471447 self .run_module (['use' , path ])
14481448 else :
1449- path = path . rstrip ( os . path . sep )
1449+ path = normalize_path ( path )
14501450 cur_mod_path = os .environ .get ('MODULEPATH' )
14511451 if cur_mod_path is None :
14521452 new_mod_path = path
@@ -1467,7 +1467,7 @@ def unuse(self, path):
14671467 self .log .debug ('Changing MODULEPATH from %s to <unset>' % cur_mod_path )
14681468 del os .environ ['MODULEPATH' ]
14691469 else :
1470- path = path . rstrip ( os . path . sep )
1470+ path = normalize_path ( path )
14711471 new_mod_path = ':' .join (p for p in cur_mod_path .split (':' ) if p != path )
14721472 if new_mod_path != cur_mod_path :
14731473 self .log .debug ('Changing MODULEPATH from %s to %s' % (cur_mod_path , new_mod_path ))
@@ -1618,12 +1618,17 @@ def get_software_version(name):
16181618 return version
16191619
16201620
1621- def curr_module_paths ():
1621+ def curr_module_paths (normalize = False ):
16221622 """
16231623 Return a list of current module paths.
1624+
1625+ :param normalize: Normalize the paths
16241626 """
16251627 # avoid empty or nonexistent paths, which don't make any sense
1626- return [p for p in os .environ .get ('MODULEPATH' , '' ).split (':' ) if p and os .path .exists (p )]
1628+ module_paths = (p for p in os .environ .get ('MODULEPATH' , '' ).split (':' ) if p and os .path .exists (p ))
1629+ if normalize :
1630+ module_paths = (normalize_path (p ) for p in module_paths )
1631+ return list (module_paths )
16271632
16281633
16291634def mk_module_path (paths ):
0 commit comments