From bf2565920fddc8181bb6397b05a3727cd08f1d56 Mon Sep 17 00:00:00 2001 From: nanoric Date: Mon, 7 Jan 2019 02:42:55 -0400 Subject: [PATCH] [Add] added format_check.py --- travis/format_check.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 travis/format_check.py diff --git a/travis/format_check.py b/travis/format_check.py new file mode 100644 index 00000000..c1455f19 --- /dev/null +++ b/travis/format_check.py @@ -0,0 +1,27 @@ +import logging +import os + +from yapf.yapflib.yapf_api import FormatFile + +logger = logging.Logger(__file__) + +if __name__ == '__main__': + has_changed = False + for root, dir, filenames in os.walk("vnpy"): + for filename in filenames: + basename, ext = os.path.splitext(filename) + if ext == '.py': + path = os.path.join(root, filename) + reformatted_code, encoding, changed = FormatFile(filename=path, + style_config='.style.yapf', + print_diff=True, + verify=False, + in_place=False, + logger=None + ) + if changed: + has_changed = True + logger.warning("File {} not formatted!".format(path)) + else: + logger.info("File {} is formatted!".format(path)) + exit(has_changed)