mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Fix call to flake8 broken when using distro module during test-tidy
This commit is contained in:
parent
4d6f28df35
commit
ff50cdb183
1 changed files with 7 additions and 16 deletions
|
@ -9,14 +9,12 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import contextlib
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import imp
|
import imp
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from io import StringIO
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -327,28 +325,21 @@ def check_by_line(file_name, lines):
|
||||||
|
|
||||||
|
|
||||||
def check_flake8(file_name, contents):
|
def check_flake8(file_name, contents):
|
||||||
from flake8.main import check_code
|
|
||||||
|
|
||||||
if not file_name.endswith(".py"):
|
if not file_name.endswith(".py"):
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def stdout_redirect(where):
|
|
||||||
sys.stdout = where
|
|
||||||
try:
|
|
||||||
yield where
|
|
||||||
finally:
|
|
||||||
sys.stdout = sys.__stdout__
|
|
||||||
|
|
||||||
ignore = {
|
ignore = {
|
||||||
"W291", # trailing whitespace; the standard tidy process will enforce no trailing whitespace
|
"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
|
"E501", # 80 character line length; the standard tidy process will enforce line length
|
||||||
}
|
}
|
||||||
|
|
||||||
output = StringIO()
|
output = ""
|
||||||
with stdout_redirect(output):
|
try:
|
||||||
check_code(contents, ignore=ignore)
|
args = ["flake8", "--ignore=" + ",".join(ignore), file_name]
|
||||||
for error in output.getvalue().splitlines():
|
subprocess.check_output(args)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
output = e.output
|
||||||
|
for error in output.splitlines():
|
||||||
_, line_num, _, message = error.split(":", 3)
|
_, line_num, _, message = error.split(":", 3)
|
||||||
yield line_num, message.strip()
|
yield line_num, message.strip()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue