Tools: Improved flake8 speed, ignore, and exclude

This commit is contained in:
TunaLobster 2022-06-24 14:55:35 -05:00 committed by Peter Barker
parent ff7832510d
commit e77ab54de1
2 changed files with 16 additions and 8 deletions

View File

@ -1,5 +1,5 @@
[flake8] [flake8]
ignore = extend-ignore =
# H301: one import per line # H301: one import per line
H301, H301,
# H306: imports not in alphabetical order (time, os) # H306: imports not in alphabetical order (time, os)
@ -15,4 +15,9 @@ ignore =
# E221 multiple spaces before operator # E221 multiple spaces before operator
E221 E221
extend-exclude =
build,
modules,
.git
max-line-length = 127 max-line-length = 127

View File

@ -19,16 +19,18 @@ os.environ['PYTHONUNBUFFERED'] = '1'
class Flake8Checker(object): class Flake8Checker(object):
def __init__(self): def __init__(self):
self.retcode = 0 self.retcode = 0
self.files_to_check = []
def progress(self, string): def progress(self, string):
print("****** %s" % (string,)) print("****** %s" % (string,))
def check(self, filepath): def check(self):
self.progress("Checking (%s)" % filepath) for path in self.files_to_check:
retcode = subprocess.call(["flake8", filepath]) self.progress("Checking (%s)" % path)
if retcode != 0: ret = subprocess.run(["flake8", "--show-source"] + self.files_to_check,
self.progress("File (%s) failed with retcode (%s)" % stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
(filepath, retcode)) if ret.returncode != 0:
self.progress("Flake8 check failed: (%s)" % (ret.stdout))
self.retcode = 1 self.retcode = 1
def run(self): def run(self):
@ -40,7 +42,8 @@ class Flake8Checker(object):
content = open(filepath).read() content = open(filepath).read()
if "AP_FLAKE8_CLEAN" not in content: if "AP_FLAKE8_CLEAN" not in content:
continue continue
self.check(filepath) self.files_to_check.append(filepath)
self.check()
return self.retcode return self.retcode