Show More
@@ -1,38 +1,51 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
3 | # Filter output by pyflakes to control which warnings we check |
|
3 | # Filter output by pyflakes to control which warnings we check | |
4 |
|
4 | |||
5 | import sys, re, os |
|
5 | import sys, re, os | |
6 |
|
6 | |||
7 |
def makekey( |
|
7 | def makekey(typeandline): | |
8 | # "path/file:line: message" |
|
8 | """ | |
9 | match = re.search(r"(line \d+)", message) |
|
9 | for sorting lines by: msgtype, path/to/file, lineno, message | |
10 | line = '' |
|
10 | ||
11 | if match: |
|
11 | typeandline is a sequence of a message type and the entire message line | |
12 | line = match.group(0) |
|
12 | the message line format is path/to/file:line: message | |
13 | message = re.sub(r"(line \d+)", '', message) |
|
13 | ||
14 | return re.sub(r"([^:]*):([^:]+):([^']*)('[^']*')(.*)$", |
|
14 | >>> makekey((3, 'example.py:36: any message')) | |
15 | r'\3:\5:\4:\1:\2:' + line, |
|
15 | (3, 'example.py', 36, ' any message') | |
16 | message) |
|
16 | >>> makekey((7, 'path/to/file.py:68: dummy message')) | |
|
17 | (7, 'path/to/file.py', 68, ' dummy message') | |||
|
18 | >>> makekey((2, 'fn:88: m')) > makekey((2, 'fn:9: m')) | |||
|
19 | True | |||
|
20 | """ | |||
|
21 | ||||
|
22 | msgtype, line = typeandline | |||
|
23 | fname, line, message = line.split(":", 2) | |||
|
24 | # line as int for ordering 9 before 88 | |||
|
25 | return msgtype, fname, int(line), message | |||
|
26 | ||||
17 |
|
27 | |||
18 | lines = [] |
|
28 | lines = [] | |
19 | for line in sys.stdin: |
|
29 | for line in sys.stdin: | |
20 | # We whitelist tests |
|
30 | # We whitelist tests (see more messages in pyflakes.messages) | |
21 | pats = [ |
|
31 | pats = [ | |
22 | r"imported but unused", |
|
32 | r"imported but unused", | |
23 | r"local variable '.*' is assigned to but never used", |
|
33 | r"local variable '.*' is assigned to but never used", | |
24 | r"unable to detect undefined names", |
|
34 | r"unable to detect undefined names", | |
25 | ] |
|
35 | ] | |
26 | if not re.search('|'.join(pats), line): |
|
36 | for msgtype, pat in enumerate(pats): | |
27 | continue |
|
37 | if re.search(pat, line): | |
|
38 | break # pattern matches | |||
|
39 | else: | |||
|
40 | continue # no pattern matched, next line | |||
28 | fn = line.split(':', 1)[0] |
|
41 | fn = line.split(':', 1)[0] | |
29 | f = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), fn)) |
|
42 | f = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), fn)) | |
30 | data = f.read() |
|
43 | data = f.read() | |
31 | f.close() |
|
44 | f.close() | |
32 | if 'no-check-code' in data: |
|
45 | if 'no-check-code' in data: | |
33 | continue |
|
46 | continue | |
34 | lines.append(line) |
|
47 | lines.append((msgtype, line)) | |
35 |
|
48 | |||
36 | for line in sorted(lines, key = makekey): |
|
49 | for msgtype, line in sorted(lines, key = makekey): | |
37 | sys.stdout.write(line) |
|
50 | sys.stdout.write(line) | |
38 |
|
51 |
General Comments 0
You need to be logged in to leave comments.
Login now