Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed easyconfig.update to be able to specify not to allow duplicate values #2657

Merged
merged 7 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,22 @@ def copy(self):

return ec

def update(self, key, value):
def update(self, key, value, allow_duplicate=True):
"""
Update a string configuration value with a value (i.e. append to it).
"""
prev_value = self[key]
if isinstance(prev_value, basestring):
self[key] = '%s %s ' % (prev_value, value)
if isinstance(prev_value, basestring)
mboisson marked this conversation as resolved.
Show resolved Hide resolved
mboisson marked this conversation as resolved.
Show resolved Hide resolved
if allow_duplicate or value not in prev_value:
mboisson marked this conversation as resolved.
Show resolved Hide resolved
mboisson marked this conversation as resolved.
Show resolved Hide resolved
self[key] = '%s %s ' % (prev_value, value)
elif isinstance(prev_value, list):
self[key] = prev_value + value
if allow_duplicate:
self[key] = prev_value + value
else:
for item in value:
# add only those items that aren't already in the list
if item not in prev_value:
self[key] = prev_value + [item]
else:
raise EasyBuildError("Can't update configuration value for %s, because it's not a string or list.", key)

Expand Down
12 changes: 12 additions & 0 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,18 @@ def test_update(self):
toy_patch_fn = 'toy-0.0_fix-silly-typo-in-printf-statement.patch'
self.assertEqual(ec['patches'], [toy_patch_fn, ('toy-extra.txt', 'toy-0.0'), 'foo.patch', 'bar.patch'])

# for unallowed duplicates
ec.update('configopts', 'SOME_VALUE')
configopts_tmp = ec['configopts']
ec.update('configopts', 'SOME_VALUE', allow_duplicate=False)
self.assertEquals(ec['configopts'], configopts_tmp)

# for unallowed duplicates when a list is used
ec.update('patches', ['foo2.patch', 'bar2.patch'])
patches_tmp = ec['patches'].copy()
ec.update('patches', ['foo2.patch', 'bar2.patch'], allow_duplicate=False)
self.assertEquals(ec['patches'], patches_tmp)

def test_hide_hidden_deps(self):
"""Test use of --hide-deps on hiddendependencies."""
test_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down