Skip to content

Commit

Permalink
Add warn_exists parameter also to append_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Nov 18, 2024
1 parent beeceed commit 0c949e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions easybuild/tools/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _filter_paths(self, key, paths, warn_exists=True):
filtered_paths = None
return filtered_paths

def append_paths(self, key, paths, allow_abs=False, expand_relpaths=True, delim=':'):
def append_paths(self, key, paths, allow_abs=False, expand_relpaths=True, delim=':', warn_exists=True):
"""
Generate append-path statements for the given list of paths.
Expand All @@ -250,8 +250,9 @@ def append_paths(self, key, paths, allow_abs=False, expand_relpaths=True, delim=
:param allow_abs: allow providing of absolute paths
:param expand_relpaths: expand relative paths into absolute paths (by prefixing install dir)
:param delim: delimiter used between paths
:param warn_exists: Show a warning if any path was already added to the variable
"""
paths = self._filter_paths(key, paths)
paths = self._filter_paths(key, paths, warn_exists=warn_exists)
if paths is None:
return ''
return self.update_paths(key, paths, prepend=False, allow_abs=allow_abs, expand_relpaths=expand_relpaths,
Expand Down
11 changes: 7 additions & 4 deletions test/framework/module_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,16 @@ def append_paths(*args, **kwargs):
# check for warning that is printed when same path is added multiple times
with self.modgen.start_module_creation():
self.modgen.append_paths('TEST', 'path1')
self.mock_stderr(True)
self.modgen.append_paths('TEST', 'path1')
stderr = self.get_stderr()
self.mock_stderr(False)
with self.mocked_stdout_stderr():
self.modgen.append_paths('TEST', 'path1')
stderr = self.get_stderr()
expected_warning = "\nWARNING: Suppressed adding the following path(s) to $TEST of the module "
expected_warning += "as they were already added: path1\n\n"
self.assertEqual(stderr, expected_warning)
with self.mocked_stdout_stderr():
self.modgen.append_paths('TEST', 'path1', warn_exists=False)
stderr = self.get_stderr()
self.assertEqual(stderr, '')

def test_module_extensions(self):
"""test the extensions() for extensions"""
Expand Down

0 comments on commit 0c949e7

Please sign in to comment.