tests/filterpyflakes.py
author Idan Kamara <idankk86@gmail.com>
Mon, 25 Jul 2011 15:03:02 +0300
changeset 14927 2aa3e07b2f07
parent 14209 08d84bdce1a5
child 19335 77440de177f7
permissions -rwxr-xr-x
posix, windows: introduce cachestat This class contains a stat result, and possibly other file info to reliably determine between two points in time whether a file has changed. Uniquely identifying a file gives us that reliability because we either atomic rename or append. So one of two will happen: the file 'id' will change, or the size of the file will change. posix implements it simply by calling os.stat() and checking if the result has st_ino. For now on Windows we always assume the path is uncacheable. This can be improved on NTFS due to file IDs: http://msdn.microsoft.com/en-us/library/aa363788(v=vs.85).aspx So we need to find out if a file path is on an NTFS drive, for that we have: - GetVolumeInformation, which unfortunately only works with a root path (but is available on XP) - GetVolumeInformationByHandleW, works on a full file path but requires Vista or higher
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     1
#!/usr/bin/env python
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     2
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     3
# Filter output by pyflakes to control which warnings we check
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     4
14209
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
     5
import sys, re, os
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
     6
14173
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
     7
def makekey(message):
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
     8
    # "path/file:line: message"
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
     9
    match = re.search(r"(line \d+)", message)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    10
    line = ''
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    11
    if match:
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    12
        line = match.group(0)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    13
        message = re.sub(r"(line \d+)", '', message)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    14
    return re.sub(r"([^:]*):([^:]+):([^']*)('[^']*')(.*)$",
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    15
                  r'\3:\5:\4:\1:\2:' + line,
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    16
                  message)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    17
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    18
lines = []
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    19
for line in sys.stdin:
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    20
    # We whitelist tests
14175
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    21
    pats = [
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    22
            r"imported but unused",
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    23
            r"local variable '.*' is assigned to but never used",
14176
dea68bddfb87 test: add pyflakes checking for unable to detect undefined names
timeless <timeless@mozdev.org>
parents: 14175
diff changeset
    24
            r"unable to detect undefined names",
14175
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    25
           ]
b452abffcb15 tests: add pyflakes checking for assigned to but never used
timeless <timeless@mozdev.org>
parents: 14173
diff changeset
    26
    if not re.search('|'.join(pats), line):
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    27
        continue
14209
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    28
    fn = line.split(':', 1)[0]
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    29
    f = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), fn))
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    30
    data = f.read()
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    31
    f.close()
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    32
    if 'no-check-code' in data:
08d84bdce1a5 pyflakes: ignore files marked no-check-code
Augie Fackler <durin42@gmail.com>
parents: 14176
diff changeset
    33
        continue
14173
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    34
    lines.append(line)
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    35
419539ea79cb test-pyflake: improve sorting algorithm
timeless <timeless@mozdev.org>
parents: 14140
diff changeset
    36
for line in sorted(lines, key = makekey):
14140
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    37
    sys.stdout.write(line)
82f0412ef7de tests: add pyflakes checking for unused imports
timeless <timeless@mozdev.org>
parents:
diff changeset
    38
print