Skip to content

Commit 677ad38

Browse files
author
Alan O'Cais
committed
Add test and make sure we use method for removing duplicates that respects order
1 parent 633e870 commit 677ad38

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

easybuild/framework/easyblock.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ def make_module_req(self):
13741374
if self.dry_run:
13751375
self.dry_run_msg(" $%s: %s" % (key, ', '.join(reqs)))
13761376
# Don't expand globs or do any filtering below for dry run
1377-
paths = sorted(reqs)
1377+
paths = reqs
13781378
else:
13791379
# Expand globs but only if the string is non-empty
13801380
# empty string is a valid value here (i.e. to prepend the installation prefix, cfr $CUDA_HOME)
@@ -1395,22 +1395,26 @@ def make_module_req(self):
13951395
if fixed_paths != paths:
13961396
self.log.info("Fixed symlink lib64 in paths for %s: %s -> %s", key, paths, fixed_paths)
13971397
paths = fixed_paths
1398-
# Use a set to remove duplicates, e.g. by having lib64 and lib which get fixed to lib and lib above
1399-
paths = set(paths)
1398+
# remove duplicate paths
1399+
# don't use 'set' here, since order in 'paths' is important!
1400+
uniq_paths = []
1401+
for path in paths:
1402+
if path not in uniq_paths:
1403+
uniq_paths.append(path)
14001404
if key in keys_requiring_files:
14011405
# only retain paths that contain at least one file
14021406
retained_paths = [
1403-
path for path in paths
1407+
path for path in uniq_paths
14041408
if os.path.isdir(os.path.join(self.installdir, path))
14051409
and dir_contains_files(os.path.join(self.installdir, path))
14061410
]
1407-
if retained_paths != paths:
1411+
if retained_paths != uniq_paths:
14081412
self.log.info("Only retaining paths for %s that contain at least one file: %s -> %s",
14091413
key, paths, retained_paths)
1410-
paths = retained_paths
1414+
uniq_paths = retained_paths
14111415

1412-
if paths:
1413-
lines.append(self.module_generator.prepend_paths(key, paths))
1416+
if uniq_paths:
1417+
lines.append(self.module_generator.prepend_paths(key, uniq_paths))
14141418
if self.dry_run:
14151419
self.dry_run_msg('')
14161420

test/framework/easyblock.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,31 @@ def test_make_module_req(self):
421421
else:
422422
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
423423

424+
# check for correct order of prepend statements when providing a list (and that no duplicates are allowed)
425+
eb.make_module_req_guess = lambda: {'LD_LIBRARY_PATH': ['lib/pathC', 'lib/pathA', 'lib/pathB', 'lib/pathA']}
426+
for path in ['pathA', 'pathB', 'pathC']:
427+
os.mkdir(os.path.join(eb.installdir, 'lib', path))
428+
open(os.path.join(eb.installdir, 'lib', path,'libfoo.so'), 'w').write('test')
429+
txt = eb.make_module_req()
430+
if get_module_syntax() == 'Tcl':
431+
self.assertTrue(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathC\n" +
432+
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n" +
433+
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathB\n",
434+
txt, re.M))
435+
self.assertFalse(re.search(r"\nprepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathB\n" +
436+
r"prepend-path\s+LD_LIBRARY_PATH\s+\$root/lib/pathA\n",
437+
txt, re.M))
438+
elif get_module_syntax() == 'Lua':
439+
self.assertTrue(re.search(r'\nprepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathC"\)\)\n' +
440+
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathA"\)\)\n' +
441+
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathB"\)\)\n',
442+
txt, re.M))
443+
self.assertFalse(re.search(r'\nprepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathB"\)\)\n' +
444+
r'prepend_path\("LD_LIBRARY_PATH", pathJoin\(root, "lib/pathA"\)\)\n',
445+
txt, re.M))
446+
else:
447+
self.assertTrue(False, "Unknown module syntax: %s" % get_module_syntax())
448+
424449
# cleanup
425450
eb.close_log()
426451
os.remove(eb.logfile)

0 commit comments

Comments
 (0)