@@ -1473,15 +1473,16 @@ def apply_regex_substitutions(paths, regex_subs, backup='.orig.eb', on_missing_m
14731473 :param paths: list of paths to files to patch (or just a single filepath)
14741474 :param regex_subs: list of substitutions to apply, specified as (<regexp pattern>, <replacement string>)
14751475 :param backup: create backup of original file with specified suffix (no backup if value evaluates to False)
1476- :param on_missing_match: Define what to do when the file when no match was found in the file.
1476+ :param on_missing_match: Define what to do when no match was found in the file.
14771477 Can be 'error' to raise an error, 'warn' to print a warning or 'ignore' to do nothing
14781478 Defaults to value of --strict
14791479 """
14801480 if on_missing_match is None :
14811481 on_missing_match = build_option ('strict' )
1482- ALLOWED_VALUES = (run .ERROR , run .WARN , run .IGNORE )
1483- if on_missing_match not in ALLOWED_VALUES :
1484- raise EasyBuildError ('Invalid value passed to on_missing_match: %s' , on_missing_match )
1482+ allowed_values = (run .ERROR , run .WARN , run .IGNORE )
1483+ if on_missing_match not in allowed_values :
1484+ raise EasyBuildError ('Invalid value passed to on_missing_match: %s (allowed: %s)' ,
1485+ on_missing_match , ', ' .join (allowed_values ))
14851486
14861487 if isinstance (paths , string_type ):
14871488 paths = [paths ]
@@ -1537,9 +1538,15 @@ def apply_regex_substitutions(paths, regex_subs, backup='.orig.eb', on_missing_m
15371538 if on_missing_match == run .ERROR :
15381539 raise EasyBuildError (msg )
15391540 elif on_missing_match == run .WARN :
1540- print_warning (msg )
1541+ _log . warning (msg )
15411542 else :
1542- _log .info (msg )
1543+ msg = 'Nothing found to replace in %s' % path
1544+ if on_missing_match == run .ERROR :
1545+ raise EasyBuildError (msg )
1546+ elif on_missing_match == run .WARN :
1547+ print_warning (msg )
1548+ else :
1549+ _log .info (msg )
15431550
15441551 except (IOError , OSError ) as err :
15451552 raise EasyBuildError ("Failed to patch %s: %s" , path , err )
0 commit comments