vnpy/tools/ci/format_check.py

29 lines
940 B
Python
Raw Normal View History

2019-01-07 06:42:55 +00:00
import logging
import os
from yapf.yapflib.yapf_api import FormatFile
logger = logging.Logger(__file__)
2019-01-26 09:24:38 +00:00
if __name__ == "__main__":
2019-01-07 06:42:55 +00:00
has_changed = False
for root, dir, filenames in os.walk("vnpy"):
for filename in filenames:
basename, ext = os.path.splitext(filename)
2019-01-26 09:24:38 +00:00
if ext == ".py":
2019-01-07 06:42:55 +00:00
path = os.path.join(root, filename)
2019-01-26 09:24:38 +00:00
reformatted_code, encoding, changed = FormatFile(
filename=path,
style_config=".style.yapf",
print_diff=True,
verify=False,
in_place=False,
logger=None,
)
2019-01-07 06:42:55 +00:00
if changed:
has_changed = True
logger.warning("File {} not formatted!".format(path))
else:
logger.info("File {} is formatted!".format(path))
exit(has_changed)