Show More
@@ -1,59 +1,58 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | 3 | # Filter output by pyflakes to control which warnings we check |
|
4 | 4 | |
|
5 | 5 | import sys, re, os |
|
6 | 6 | |
|
7 | 7 | def makekey(typeandline): |
|
8 | 8 | """ |
|
9 | 9 | for sorting lines by: msgtype, path/to/file, lineno, message |
|
10 | 10 | |
|
11 | 11 | typeandline is a sequence of a message type and the entire message line |
|
12 | 12 | the message line format is path/to/file:line: message |
|
13 | 13 | |
|
14 | 14 | >>> makekey((3, 'example.py:36: any message')) |
|
15 | 15 | (3, 'example.py', 36, ' any message') |
|
16 | 16 | >>> makekey((7, 'path/to/file.py:68: dummy message')) |
|
17 | 17 | (7, 'path/to/file.py', 68, ' dummy message') |
|
18 | 18 | >>> makekey((2, 'fn:88: m')) > makekey((2, 'fn:9: m')) |
|
19 | 19 | True |
|
20 | 20 | """ |
|
21 | 21 | |
|
22 | 22 | msgtype, line = typeandline |
|
23 | 23 | fname, line, message = line.split(":", 2) |
|
24 | 24 | # line as int for ordering 9 before 88 |
|
25 | 25 | return msgtype, fname, int(line), message |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | lines = [] |
|
29 | 29 | for line in sys.stdin: |
|
30 | 30 | # We whitelist tests (see more messages in pyflakes.messages) |
|
31 | 31 | pats = [ |
|
32 | 32 | (r"imported but unused", None), |
|
33 | 33 | (r"local variable '.*' is assigned to but never used", None), |
|
34 | 34 | (r"unable to detect undefined names", None), |
|
35 | (r"undefined name '.*'", | |
|
36 | r"undefined name 'memoryview'") | |
|
35 | 37 | ] |
|
36 | if sys.version_info >= (2, 7): | |
|
37 | pats.append((r"undefined name '.*'", None)) | |
|
38 | else: | |
|
39 | pats.append((r"undefined name '.*'", r"undefined name 'memoryview'")) | |
|
38 | ||
|
40 | 39 | for msgtype, (pat, excl) in enumerate(pats): |
|
41 | 40 | if re.search(pat, line) and (not excl or not re.search(excl, line)): |
|
42 | 41 | break # pattern matches |
|
43 | 42 | else: |
|
44 | 43 | continue # no pattern matched, next line |
|
45 | 44 | fn = line.split(':', 1)[0] |
|
46 | 45 | f = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), fn)) |
|
47 | 46 | data = f.read() |
|
48 | 47 | f.close() |
|
49 | 48 | if 'no-' 'check-code' in data: |
|
50 | 49 | continue |
|
51 | 50 | lines.append((msgtype, line)) |
|
52 | 51 | |
|
53 | 52 | for msgtype, line in sorted(lines, key=makekey): |
|
54 | 53 | sys.stdout.write(line) |
|
55 | 54 | |
|
56 | 55 | |
|
57 | 56 | # self test of "undefined name" detection for other than 'memoryview' |
|
58 | 57 | if False: |
|
59 | 58 | print undefinedname |
@@ -1,22 +1,22 b'' | |||
|
1 | 1 | #if test-repo pyflakes |
|
2 | 2 | |
|
3 | 3 | $ cd "`dirname "$TESTDIR"`" |
|
4 | 4 | |
|
5 | 5 | run pyflakes on all tracked files ending in .py or without a file ending |
|
6 | 6 | (skipping binary file random-seed) |
|
7 | 7 | |
|
8 | 8 | $ hg locate 'set:**.py or grep("^!#.*python")' 2>/dev/null \ |
|
9 | 9 | > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" |
|
10 | 10 | contrib/win32/hgwebdir_wsgi.py:*: 'win32traceutil' imported but unused (glob) |
|
11 | 11 | setup.py:*: 'sha' imported but unused (glob) |
|
12 | 12 | setup.py:*: 'zlib' imported but unused (glob) |
|
13 | 13 | setup.py:*: 'bz2' imported but unused (glob) |
|
14 | 14 | setup.py:*: 'py2exe' imported but unused (glob) |
|
15 | 15 | tests/hghave.py:*: '_lsprof' imported but unused (glob) |
|
16 | 16 | tests/hghave.py:*: 'publish_cmdline' imported but unused (glob) |
|
17 | 17 | tests/hghave.py:*: 'pygments' imported but unused (glob) |
|
18 | 18 | tests/hghave.py:*: 'ssl' imported but unused (glob) |
|
19 | 19 | contrib/win32/hgwebdir_wsgi.py:93: 'from isapi.install import *' used; unable to detect undefined names (glob) |
|
20 |
tests/filterpyflakes.py:5 |
|
|
20 | tests/filterpyflakes.py:58: undefined name 'undefinedname' | |
|
21 | 21 | |
|
22 | 22 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now