From 684f049fcafaba2a0aa4cbf1daa07b9e49b9ae9a Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 23 Feb 2019 16:12:53 +0800 Subject: [PATCH] [Add]tools for continuous integration --- tools/ci/format_check.py | 28 ++++++++++++++++++++++++++++ tools/ci/requirements.txt | 0 2 files changed, 28 insertions(+) create mode 100644 tools/ci/format_check.py create mode 100644 tools/ci/requirements.txt diff --git a/tools/ci/format_check.py b/tools/ci/format_check.py new file mode 100644 index 00000000..b117a84e --- /dev/null +++ b/tools/ci/format_check.py @@ -0,0 +1,28 @@ +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) diff --git a/tools/ci/requirements.txt b/tools/ci/requirements.txt new file mode 100644 index 00000000..e69de29b