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