Skip to content

Commit

Permalink
Verify format of regex_subs
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Feb 10, 2025
1 parent 981e820 commit b5fcdce
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,11 +1664,14 @@ def apply_regex_substitutions(paths, regex_subs, backup='.orig.eb',
on_missing_match = build_option('strict')
allowed_values = (ERROR, IGNORE, WARN)
if on_missing_match not in allowed_values:
raise EasyBuildError('Invalid value passed to on_missing_match: %s (allowed: %s)',
on_missing_match, ', '.join(allowed_values))
raise ValueError('Invalid value passed to on_missing_match: %s (allowed: %s)',
on_missing_match, ', '.join(allowed_values))

if isinstance(paths, string_type):
paths = [paths]
if (not isinstance(regex_subs, list, tuple) or
not all(isinstance(sub, list, tuple) and len(sub) == 2 for sub in regex_subs)):
raise ValueError('Parameter regex_subs must be a list of 2-element tuples. Got: ', regex_subs)

flags = 0 if single_line else re.M
compiled_regex_subs = [(re.compile(regex, flags) if isinstance(regex, str) else regex, subtxt)
Expand Down

0 comments on commit b5fcdce

Please sign in to comment.