Unverified Commit 036b2bd8 authored by Richard Berger's avatar Richard Berger
Browse files

Add non-zero exit code on whitespace check failure

parent 61235308
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -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:
        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()