1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-28 16:12:24 +01:00
* Add black

Update pre commit

Update pre commit

add empty line

* Format with black
This commit is contained in:
Guillermo Ruffino
2021-03-07 16:03:16 -03:00
committed by GitHub
parent 2b60b0f1fa
commit 69879920eb
398 changed files with 21624 additions and 12644 deletions

View File

@@ -1,15 +1,14 @@
#!/usr/bin/env python3
from __future__ import print_function
from helpers import get_output, get_err, git_ls_files, filter_changed
import argparse
import collections
import os
import re
import sys
sys.path.append(os.path.dirname(__file__))
from helpers import get_output, git_ls_files, filter_changed
curfile = None
@@ -22,26 +21,28 @@ def print_error(file, lineno, msg):
print("\033[0;32m************* File \033[1;32m{}\033[0m".format(file))
curfile = file
print(u'{}:{} - {}'.format(file, lineno, msg))
print("{}:{} - {}".format(file, lineno, msg))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('files', nargs='*', default=[],
help='files to be processed (regex on path)')
parser.add_argument('-c', '--changed', action='store_true',
help='Only run on changed files')
parser.add_argument(
"files", nargs="*", default=[], help="files to be processed (regex on path)"
)
parser.add_argument(
"-c", "--changed", action="store_true", help="Only run on changed files"
)
args = parser.parse_args()
files = []
for path in git_ls_files():
filetypes = ('.py',)
filetypes = (".py",)
ext = os.path.splitext(path)[1]
if ext in filetypes and path.startswith('esphome'):
if ext in filetypes and path.startswith("esphome"):
path = os.path.relpath(path, os.getcwd())
files.append(path)
# Match against re
file_name_re = re.compile('|'.join(args.files))
file_name_re = re.compile("|".join(args.files))
files = [p for p in files if file_name_re.search(p)]
if args.changed:
@@ -52,34 +53,45 @@ def main():
sys.exit(0)
errors = 0
cmd = ['flake8'] + files
cmd = ["black", "--verbose", "--check"] + files
print("Running black...")
log = get_err(*cmd)
for line in log.splitlines():
WOULD_REFORMAT = "would reformat"
if line.startswith(WOULD_REFORMAT):
file_ = line[len(WOULD_REFORMAT) + 1 :]
print_error(file_, None, "Please format this file with the black formatter")
errors += 1
cmd = ["flake8"] + files
print("Running flake8...")
log = get_output(*cmd)
for line in log.splitlines():
line = line.split(':', 4)
line = line.split(":", 4)
if len(line) < 4:
continue
file_ = line[0]
linno = line[1]
msg = (':'.join(line[3:])).strip()
msg = (":".join(line[3:])).strip()
print_error(file_, linno, msg)
errors += 1
cmd = ['pylint', '-f', 'parseable', '--persistent=n'] + files
cmd = ["pylint", "-f", "parseable", "--persistent=n"] + files
print("Running pylint...")
log = get_output(*cmd)
for line in log.splitlines():
line = line.split(':', 3)
line = line.split(":", 3)
if len(line) < 3:
continue
file_ = line[0]
linno = line[1]
msg = (':'.join(line[2:])).strip()
msg = (":".join(line[2:])).strip()
print_error(file_, linno, msg)
errors += 1
sys.exit(errors)
if __name__ == '__main__':
if __name__ == "__main__":
main()