Skip to content

Commit

Permalink
Merge pull request #4667 from Crivella/fix-easystack_multiple_call
Browse files Browse the repository at this point in the history
Added possibility to call `amend/try-amend` multiple times from easystack
  • Loading branch information
boegel authored Nov 6, 2024
2 parents 7ca20ce + 201aba6 commit d700144
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,7 @@ def opts_dict_to_eb_opts(args_dict):
:return: a list of strings representing command-line options for the 'eb' command
"""

allow_multiple_calls = ['amend', 'try-amend']
_log.debug("Converting dictionary %s to argument list" % args_dict)
args = []
for arg in sorted(args_dict):
Expand All @@ -2011,14 +2012,18 @@ def opts_dict_to_eb_opts(args_dict):
prefix = '--'
option = prefix + str(arg)
value = args_dict[arg]
if isinstance(value, (list, tuple)):
value = ','.join(str(x) for x in value)

if value in [True, None]:
if str(arg) in allow_multiple_calls:
if not isinstance(value, (list, tuple)):
value = [value]
args.extend(option + '=' + str(x) for x in value)
elif value in [True, None]:
args.append(option)
elif value is False:
args.append('--disable-' + option[2:])
elif value is not None:
if isinstance(value, (list, tuple)):
value = ','.join(str(x) for x in value)
args.append(option + '=' + str(value))

_log.debug("Converted dictionary %s to argument list %s" % (args_dict, args))
Expand Down
9 changes: 9 additions & 0 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7253,6 +7253,15 @@ def test_opts_dict_to_eb_opts(self):
]
self.assertEqual(opts_dict_to_eb_opts(opts_dict), expected)

# multi-call options
opts_dict = {'try-amend': ['a=1', 'b=2', 'c=3']}
expected = ['--try-amend=a=1', '--try-amend=b=2', '--try-amend=c=3']
self.assertEqual(opts_dict_to_eb_opts(opts_dict), expected)

opts_dict = {'amend': ['a=1', 'b=2', 'c=3']}
expected = ['--amend=a=1', '--amend=b=2', '--amend=c=3']
self.assertEqual(opts_dict_to_eb_opts(opts_dict), expected)


def suite():
""" returns all the testcases in this module """
Expand Down

0 comments on commit d700144

Please sign in to comment.