From 036b2bd82ce6dc7fa0b4d6575804d99a4e842e54 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 16 Jun 2020 07:06:37 -0400 Subject: [PATCH] Add non-zero exit code on whitespace check failure --- tools/coding_standard/whitespace.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/coding_standard/whitespace.py b/tools/coding_standard/whitespace.py index 04246ec704..d3f82e2bc5 100644 --- a/tools/coding_standard/whitespace.py +++ b/tools/coding_standard/whitespace.py @@ -3,6 +3,7 @@ # # Written by Richard Berger (Temple University) import os +import sys import glob import re import yaml @@ -76,6 +77,7 @@ def fix_file(path, check_result): shutil.move(newfile, path) def check_folder(directory, config, fix=False, verbose=False): + success = True files = [] for base_path in config['include']: @@ -104,14 +106,19 @@ def check_folder(directory, config, fix=False, verbose=False): if result['encoding'] == 'unknown': print("[Error] Unknown text encoding @ {}".format(path)) has_resolvable_errors = False + success = False elif result['encoding'] == 'ISO-8859-1': print("[Error] Found ISO-8859-1 encoding instead of UTF-8 @ {}".format(path)) has_resolvable_errors = True - if has_resolvable_errors and fix: - print("Applying automatic fixes to file:", path) - fix_file(path, result) + if has_resolvable_errors: + if fix: + print("Applying automatic fixes to file:", path) + fix_file(path, result) + else: + success = False + return success def main(): parser = argparse.ArgumentParser(description='Utility for detecting and fixing whitespace issues in LAMMPS') @@ -127,7 +134,8 @@ def main(): else: config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader) - check_folder(args.DIRECTORY, config, args.fix, args.verbose) + if not check_folder(args.DIRECTORY, config, args.fix, args.verbose): + sys.exit(1) if __name__ == "__main__": main()