@@ -1282,66 +1282,69 @@ def make_module_req(self):
12821282
12831283 lines = ['\n ' ]
12841284 if os .path .isdir (self .installdir ):
1285- change_dir (self .installdir )
1285+ old_dir = change_dir (self .installdir )
1286+ else :
1287+ old_dir = None
12861288
1287- if self .dry_run :
1288- self .dry_run_msg ("List of paths that would be searched and added to module file:\n " )
1289- note = "note: glob patterns are not expanded and existence checks "
1290- note += "for paths are skipped for the statements below due to dry run"
1291- lines .append (self .module_generator .comment (note ))
1292- lib64_is_symlink = False
1293- else :
1294- lib64_is_symlink = (all (os .path .isdir (path ) for path in ['lib' , 'lib64' ])
1295- and os .path .samefile ('lib' , 'lib64' ))
1289+ if self .dry_run :
1290+ self .dry_run_msg ("List of paths that would be searched and added to module file:\n " )
1291+ note = "note: glob patterns are not expanded and existence checks "
1292+ note += "for paths are skipped for the statements below due to dry run"
1293+ lines .append (self .module_generator .comment (note ))
1294+ else :
1295+ lib64_is_symlink = (all (os .path .isdir (path ) for path in ['lib' , 'lib64' ])
1296+ and os .path .samefile ('lib' , 'lib64' ))
12961297
1297- # for these environment variables, the corresponding subdirectory must include at least one file
1298- keys_requiring_files = ('CPATH' , 'LD_LIBRARY_PATH' , 'LIBRARY_PATH' , 'PATH' , 'CMAKE_LIBRARY_PATH' )
1298+ # for these environment variables, the corresponding subdirectory must include at least one file
1299+ keys_requiring_files = ('CPATH' , 'LD_LIBRARY_PATH' , 'LIBRARY_PATH' , 'PATH' , 'CMAKE_LIBRARY_PATH' )
12991300
1300- for key , reqs in sorted (requirements .items ()):
1301- if isinstance (reqs , string_type ):
1302- self .log .warning ("Hoisting string value %s into a list before iterating over it" , reqs )
1303- reqs = [reqs ]
1304- if self .dry_run :
1305- self .dry_run_msg (" $%s: %s" % (key , ', ' .join (reqs )))
1306-
1307- for path in reqs :
1308- # only use glob if the string is non-empty
1309- if path and not self .dry_run :
1310- paths = glob .glob (path )
1311- # If lib64 is just a symlink to lib we fixup the paths to avoid duplicates
1312- if lib64_is_symlink :
1313- fixed_paths = []
1314- for path in paths :
1315- if (path + os .path .sep ).startswith ('lib64' + os .path .sep ):
1316- # We only need CMAKE_LIBRARY_PATH if there is a separate lib64 path
1317- if key == 'CMAKE_LIBRARY_PATH' :
1318- continue
1319- path = path .replace ('lib64' , 'lib' , 1 )
1320- fixed_paths .append (path )
1321- if fixed_paths != paths :
1322- self .log .info ("Fixed symlink lib64 in paths for %s: %s -> %s" ,
1323- key , paths , fixed_paths )
1324- paths = fixed_paths
1325- # Use a set to remove duplicates
1326- paths = sorted (set (paths ))
1327- if paths and key in keys_requiring_files :
1328- # only retain paths that contain at least one file
1329- retained_paths = [
1330- path for path in paths
1331- if os .path .isdir (os .path .join (self .installdir , path ))
1332- and dir_contains_files (os .path .join (self .installdir , path ))
1333- ]
1334- self .log .info ("Only retaining paths for %s that contain at least one file: %s -> %s" ,
1335- key , paths , retained_paths )
1336- paths = retained_paths
1337- else :
1338- # empty string is a valid value here (i.e. to prepend the installation prefix, cfr $CUDA_HOME)
1339- paths = [path ]
1340-
1341- lines .append (self .module_generator .prepend_paths (key , paths ))
1301+ for key , reqs in sorted (requirements .items ()):
1302+ if isinstance (reqs , string_type ):
1303+ self .log .warning ("Hoisting string value %s into a list before iterating over it" , reqs )
1304+ reqs = [reqs ]
13421305 if self .dry_run :
1343- self .dry_run_msg ('' )
1344- change_dir (self .orig_workdir )
1306+ self .dry_run_msg (" $%s: %s" % (key , ', ' .join (reqs )))
1307+
1308+ for path in reqs :
1309+ # only use glob if the string is non-empty
1310+ if path and not self .dry_run :
1311+ paths = glob .glob (path )
1312+ # If lib64 is just a symlink to lib we fixup the paths to avoid duplicates
1313+ if lib64_is_symlink :
1314+ fixed_paths = []
1315+ for path in paths :
1316+ if (path + os .path .sep ).startswith ('lib64' + os .path .sep ):
1317+ # We only need CMAKE_LIBRARY_PATH if there is a separate lib64 path
1318+ if key == 'CMAKE_LIBRARY_PATH' :
1319+ continue
1320+ path = path .replace ('lib64' , 'lib' , 1 )
1321+ fixed_paths .append (path )
1322+ if fixed_paths != paths :
1323+ self .log .info ("Fixed symlink lib64 in paths for %s: %s -> %s" ,
1324+ key , paths , fixed_paths )
1325+ paths = fixed_paths
1326+ # Use a set to remove duplicates
1327+ paths = sorted (set (paths ))
1328+ if paths and key in keys_requiring_files :
1329+ # only retain paths that contain at least one file
1330+ retained_paths = [
1331+ path for path in paths
1332+ if os .path .isdir (os .path .join (self .installdir , path ))
1333+ and dir_contains_files (os .path .join (self .installdir , path ))
1334+ ]
1335+ self .log .info ("Only retaining paths for %s that contain at least one file: %s -> %s" ,
1336+ key , paths , retained_paths )
1337+ paths = retained_paths
1338+ else :
1339+ # empty string is a valid value here (i.e. to prepend the installation prefix, cfr $CUDA_HOME)
1340+ paths = [path ]
1341+
1342+ lines .append (self .module_generator .prepend_paths (key , paths ))
1343+ if self .dry_run :
1344+ self .dry_run_msg ('' )
1345+
1346+ if old_dir is not None :
1347+ change_dir (old_dir )
13451348
13461349 return '' .join (lines )
13471350
0 commit comments