Skip to content

Commit 769d5e2

Browse files
authored
Merge pull request #4440 from Flamefire/error-on-multip-pr-opts
show error when multiple PR options are passed
2 parents 19decf0 + 17bac31 commit 769d5e2

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

easybuild/main.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,23 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session
333333

334334
categorized_paths = categorize_files_by_type(eb_args)
335335

336+
set_pr_options = [opt for opt in (
337+
'new_branch_github',
338+
'new_pr',
339+
'new_pr_from_branch',
340+
'preview_pr',
341+
'sync_branch_with_develop',
342+
'sync_pr_with_develop',
343+
'update_branch_github',
344+
'update_pr',
345+
) if getattr(options, opt)
346+
]
347+
any_pr_option_set = len(set_pr_options) > 0
348+
if len(set_pr_options) > 1:
349+
raise EasyBuildError("The following options are set but incompatible: %s.\nYou can only use one at a time!",
350+
', '.join(['--' + opt.replace('_', '-') for opt in set_pr_options]))
336351
# command line options that do not require any easyconfigs to be specified
337-
pr_options = options.new_branch_github or options.new_pr or options.new_pr_from_branch or options.preview_pr
338-
pr_options = pr_options or options.sync_branch_with_develop or options.sync_pr_with_develop
339-
pr_options = pr_options or options.update_branch_github or options.update_pr
340-
no_ec_opts = [options.aggregate_regtest, options.regtest, pr_options, search_query]
352+
no_ec_opts = [options.aggregate_regtest, options.regtest, any_pr_option_set, search_query]
341353

342354
# determine paths to easyconfigs
343355
determined_paths = det_easyconfig_paths(categorized_paths['easyconfigs'])
@@ -427,9 +439,10 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session
427439
forced = options.force or options.rebuild
428440
dry_run_mode = options.dry_run or options.dry_run_short or options.missing_modules
429441

430-
keep_available_modules = forced or dry_run_mode or options.extended_dry_run or pr_options or options.copy_ec
431-
keep_available_modules = keep_available_modules or options.inject_checksums or options.sanity_check_only
432-
keep_available_modules = keep_available_modules or options.inject_checksums_to_json
442+
keep_available_modules = any((
443+
forced, dry_run_mode, options.extended_dry_run, any_pr_option_set, options.copy_ec, options.inject_checksums,
444+
options.sanity_check_only, options.inject_checksums_to_json)
445+
)
433446

434447
# skip modules that are already installed unless forced, or unless an option is used that warrants not skipping
435448
if not keep_available_modules:
@@ -448,12 +461,12 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session
448461
if len(easyconfigs) > 0:
449462
# resolve dependencies if robot is enabled, except in dry run mode
450463
# one exception: deps *are* resolved with --new-pr or --update-pr when dry run mode is enabled
451-
if options.robot and (not dry_run_mode or pr_options):
464+
if options.robot and (not dry_run_mode or any_pr_option_set):
452465
print_msg("resolving dependencies ...", log=_log, silent=testing)
453466
ordered_ecs = resolve_dependencies(easyconfigs, modtool)
454467
else:
455468
ordered_ecs = easyconfigs
456-
elif pr_options:
469+
elif any_pr_option_set:
457470
ordered_ecs = None
458471
else:
459472
print_msg("No easyconfigs left to be built.", log=_log, silent=testing)
@@ -472,7 +485,7 @@ def process_eb_args(eb_args, eb_go, cfg_settings, modtool, testing, init_session
472485
return True
473486

474487
# creating/updating PRs
475-
if pr_options:
488+
if any_pr_option_set:
476489
if options.new_pr:
477490
new_pr(categorized_paths, ordered_ecs)
478491
elif options.new_branch_github:

test/framework/options.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,6 +3915,18 @@ def test_github_review_pr(self):
39153915
self.mock_stderr(False)
39163916
self.assertNotIn("2016.04", txt)
39173917

3918+
def test_set_multiple_pr_opts(self):
3919+
"""Test that passing multiple PR options results in an error"""
3920+
test_cases = [
3921+
['--new-pr', 'dummy.eb', '--preview-pr'],
3922+
['--new-pr', 'dummy.eb', '--update-pr', '42'],
3923+
['--new-pr', 'dummy.eb', '--sync-pr-with-develop', '42'],
3924+
['--new-pr', 'dummy.eb', '--new-pr-from-branch', 'mybranch'],
3925+
]
3926+
for args in test_cases:
3927+
error_pattern = "The following options are set but incompatible.* " + args[0]
3928+
self.assertErrorRegex(EasyBuildError, error_pattern, self._run_mock_eb, args, raise_error=True)
3929+
39183930
def test_set_tmpdir(self):
39193931
"""Test set_tmpdir config function."""
39203932
self.purge_environment()

0 commit comments

Comments
 (0)