aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy/servo_tidy/tidy.py
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2019-10-20 22:29:50 +0100
committermarmeladema <xademax@gmail.com>2019-10-22 10:15:53 +0100
commitff50cdb1831c4f35c21fc922bd8be085232ad0e3 (patch)
tree2973e5bcd6ea64173f3b09c20f2383d325a136dc /python/tidy/servo_tidy/tidy.py
parent4d6f28df3563878188406c375650620378200715 (diff)
downloadservo-ff50cdb1831c4f35c21fc922bd8be085232ad0e3.tar.gz
servo-ff50cdb1831c4f35c21fc922bd8be085232ad0e3.zip
Fix call to flake8 broken when using distro module during test-tidy
Diffstat (limited to 'python/tidy/servo_tidy/tidy.py')
-rw-r--r--python/tidy/servo_tidy/tidy.py23
1 files changed, 7 insertions, 16 deletions
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index d4ad6cfde5f..1e9392dc6b7 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -9,14 +9,12 @@
from __future__ import print_function
-import contextlib
import fnmatch
import imp
import itertools
import json
import os
import re
-from io import StringIO
import subprocess
import sys
@@ -327,28 +325,21 @@ def check_by_line(file_name, lines):
def check_flake8(file_name, contents):
- from flake8.main import check_code
-
if not file_name.endswith(".py"):
raise StopIteration
- @contextlib.contextmanager
- def stdout_redirect(where):
- sys.stdout = where
- try:
- yield where
- finally:
- sys.stdout = sys.__stdout__
-
ignore = {
"W291", # trailing whitespace; the standard tidy process will enforce no trailing whitespace
"E501", # 80 character line length; the standard tidy process will enforce line length
}
- output = StringIO()
- with stdout_redirect(output):
- check_code(contents, ignore=ignore)
- for error in output.getvalue().splitlines():
+ output = ""
+ try:
+ args = ["flake8", "--ignore=" + ",".join(ignore), file_name]
+ subprocess.check_output(args)
+ except subprocess.CalledProcessError as e:
+ output = e.output
+ for error in output.splitlines():
_, line_num, _, message = error.split(":", 3)
yield line_num, message.strip()