Skip to content

Commit

Permalink
Merge pull request #1300 from boegel/purify_prepend_paths
Browse files Browse the repository at this point in the history
don't modify values of 'paths' list passed as argument to prepend_paths
  • Loading branch information
boegel committed Jun 16, 2015
2 parents eb27aaf + d3c3905 commit df7cb20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,21 @@ def prepend_paths(self, key, paths, allow_abs=False):
self.log.debug("Wrapping %s into a list before using it to prepend path %s" % (paths, key))
paths = [paths]

for i, path in enumerate(paths):
abspaths = []
for path in paths:
if os.path.isabs(path) and not allow_abs:
raise EasyBuildError("Absolute path %s passed to prepend_paths which only expects relative paths.",
path)
elif not os.path.isabs(path):
# prepend $root (= installdir) for (non-empty) relative paths
if path:
paths[i] = os.path.join('$root', path)
abspaths.append(os.path.join('$root', path))
else:
paths[i] = '$root'
abspaths.append('$root')
else:
abspaths.append(path)

statements = [template % (key, p) for p in paths]
statements = [template % (key, p) for p in abspaths]
return ''.join(statements)

def use(self, paths):
Expand Down
5 changes: 4 additions & 1 deletion test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ def test_prepend_paths(self):
"prepend-path\tkey\t\t$root/path2\n",
"prepend-path\tkey\t\t$root\n",
])
self.assertEqual(expected, self.modgen.prepend_paths("key", ["path1", "path2", '']))
paths = ['path1', 'path2', '']
self.assertEqual(expected, self.modgen.prepend_paths("key", paths))
# 2nd call should still give same result, no side-effects like manipulating passed list 'paths'!
self.assertEqual(expected, self.modgen.prepend_paths("key", paths))

expected = "prepend-path\tbar\t\t$root/foo\n"
self.assertEqual(expected, self.modgen.prepend_paths("bar", "foo"))
Expand Down

0 comments on commit df7cb20

Please sign in to comment.