annotate MoinMoin/_tests/pep8.py @ 3910:6fbfffffc4d1

Insert moins path more aggressively into sys.path to win the race against py.test, do insertions less often in make_test_wiki
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 31 Jul 2008 14:17:19 +0200
parents 70b1a82ec75b
children
rev   line source
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 #!/usr/bin/python
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 # pep8.py - Check Python source code formatting, according to PEP 8
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 # Copyright (C) 2006 Johann C. Rocholl <johann@browsershots.org>
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 #
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 # Permission is hereby granted, free of charge, to any person
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 # obtaining a copy of this software and associated documentation files
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 # (the "Software"), to deal in the Software without restriction,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 # including without limitation the rights to use, copy, modify, merge,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 # publish, distribute, sublicense, and/or sell copies of the Software,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 # and to permit persons to whom the Software is furnished to do so,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 # subject to the following conditions:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 #
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 # The above copyright notice and this permission notice shall be
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 # included in all copies or substantial portions of the Software.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 #
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 # SOFTWARE.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 Check Python source code formatting, according to PEP 8:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 http://www.python.org/dev/peps/pep-0008/
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 For usage and a list of options, try this:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 $ python pep8.py -h
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 This program and its regression test suite live here:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 http://svn.browsershots.org/trunk/devtools/pep8/
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 http://trac.browsershots.org/browser/trunk/devtools/pep8/
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 Groups of errors and warnings:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 E errors
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 W warnings
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 100 indentation
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 200 whitespace
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 300 blank lines
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 400 imports
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 500 line length
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 600 deprecation
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 700 statements
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 You can add checks to this program by writing plugins. Each plugin is
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 a simple function that is called for each line of source code, either
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 physical or logical.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 Physical line:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 - Raw line of text from the input file.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 Logical line:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 - Multi-line statements converted to a single line.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 - Stripped left and right.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 - Contents of strings replaced with 'xxx' of same length.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 - Comments removed.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 The check function requests physical or logical lines by the name of
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 the first argument:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 def maximum_line_length(physical_line)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 def extraneous_whitespace(logical_line)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 def blank_lines(logical_line, blank_lines, indent_level, line_number)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67 The last example above demonstrates how check plugins can request
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 additional information with extra arguments. All attributes of the
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 Checker object are available. Some examples:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 lines: a list of the raw lines from the input file
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 tokens: the tokens that contribute to this logical line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 line_number: line number in the input file
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 blank_lines: blank lines before this one
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 indent_char: first indentation character in this file (' ' or '\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 indent_level: indentation (with tabs expanded to multiples of 8)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 previous_indent_level: indentation on previous line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 previous_logical: previous logical line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 The docstring of each check function shall be the relevant part of
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 text from PEP 8. It is printed if the user enables --show-pep8.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 import os
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 import sys
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 import re
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 import time
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 import inspect
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 import tokenize
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 from optparse import OptionParser
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 from keyword import iskeyword
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 from fnmatch import fnmatch
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 __version__ = '0.2.0'
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 __revision__ = '$Rev$'
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 default_exclude = '.svn,CVS,*.pyc,*.pyo'
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 indent_match = re.compile(r'([ \t]*)').match
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 raise_comma_match = re.compile(r'raise\s+\w+\s*(,)').match
2445
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
102 equals_boolean_search = re.compile(r'([!=]=\s*(True|False))|((True|False)\s*[!=]=)').search
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
103 equals_None_search = re.compile(r'([!=]=\s*None)|(None\s*[!=]=)').search
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104
2446
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
105 not_one_ws_around_operators_match = re.compile(r'^[^\(\[]+[^\s](\+|\-|\*|/|%|\^|&|\||=|<|>|>>|<<|\+=|\-=|\*=|/=|%=|\^=|&=|\|=|==|<=|>=|>>=|<<=|!=|<>)[^\s][^\)\]]+$').match
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
106
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 operators = """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 + - * / % ^ & | = < > >> <<
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 += -= *= /= %= ^= &= |= == <= >= >>= <<=
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 != <> :
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 in is or not and
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 """.split()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 options = None
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 args = None
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 # Plugins (check functions) for physical lines
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 def tabs_or_spaces(physical_line, indent_char):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 Never mix tabs and spaces.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 The most popular way of indenting Python is with spaces only. The
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 second-most popular way is with tabs only. Code indented with a mixture
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 of tabs and spaces should be converted to using spaces exclusively. When
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 invoking the Python command line interpreter with the -t option, it issues
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 warnings about code that illegally mixes tabs and spaces. When using -tt
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 these warnings become errors. These options are highly recommended!
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 indent = indent_match(physical_line).group(1)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 for offset, char in enumerate(indent):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 if char != indent_char:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 return offset, "E101 indentation contains mixed spaces and tabs"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 def tabs_obsolete(physical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 For new projects, spaces-only are strongly recommended over tabs. Most
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 editors have features that make this easy to do.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 indent = indent_match(physical_line).group(1)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 if indent.count('\t'):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147 return indent.index('\t'), "W191 indentation contains tabs"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 def trailing_whitespace(physical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 JCR: Trailing whitespace is superfluous.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 physical_line = physical_line.rstrip('\n') # chr(10), newline
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 physical_line = physical_line.rstrip('\r') # chr(13), carriage return
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 stripped = physical_line.rstrip()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 if physical_line != stripped:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 return len(stripped), "W291 trailing whitespace"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 def trailing_blank_lines(physical_line, lines, line_number):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 JCR: Trailing blank lines are superfluous.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 if physical_line.strip() == '' and line_number == len(lines):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 return 0, "W391 blank line at end of file"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 def missing_newline(physical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 JCR: The last line should have a newline.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 if physical_line.rstrip() == physical_line:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 return len(physical_line), "W292 no newline at end of file"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 def maximum_line_length(physical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 Limit all lines to a maximum of 79 characters.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 There are still many devices around that are limited to 80 character
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183 lines; plus, limiting windows to 80 characters makes it possible to have
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 several windows side-by-side. The default wrapping on such devices looks
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 ugly. Therefore, please limit all lines to a maximum of 79 characters.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186 For flowing long blocks of text (docstrings or comments), limiting the
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 length to 72 characters is recommended.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189 length = len(physical_line.rstrip())
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 if length > 79:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 return 79, "E501 line too long (%d characters)" % length
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193
2288
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
194 def crlf_lines(physical_line):
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
195 """
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
196 Line contains CR (e.g. as a CRLF line ending).
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
197
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
198 Many free software projects have a strong focus on POSIX platforms (like
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
199 Linux, *BSD, Unix, Mac OS X, etc.) and they all use LF-only line endings.
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
200 Only Win32 platform uses CRLF line endings.
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
201 So if you have a Win32-only source code using CRLF line endings, you might
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
202 want to exclude this test.
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
203 """
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
204 pos = physical_line.find('\r')
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
205 if pos >= 0:
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
206 return pos, "W293 line contains CR char(s)"
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
207
0f44ed5ed2a1 test_sourcecode: remove tests that pep8 checker also does, enable warnings, add crlf check to pep8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2283
diff changeset
208
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 # Plugins (check functions) for logical lines
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 def blank_lines(logical_line, blank_lines, indent_level, line_number,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 previous_logical):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 Separate top-level function and class definitions with two blank lines.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 Method definitions inside a class are separated by a single blank line.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 Extra blank lines may be used (sparingly) to separate groups of related
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 functions. Blank lines may be omitted between a bunch of related
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 one-liners (e.g. a set of dummy implementations).
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 Use blank lines in functions, sparingly, to indicate logical sections.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 if line_number == 1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228 return # Don't expect blank lines before the first line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 if previous_logical.startswith('@'):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230 return # Don't expect blank lines after function decorator
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
231 if (logical_line.startswith('def ') or
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
232 logical_line.startswith('class ') or
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233 logical_line.startswith('@')):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 if indent_level > 0 and blank_lines != 1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235 return 0, "E301 expected 1 blank line, found %d" % blank_lines
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
236 if indent_level == 0 and blank_lines != 2:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237 return 0, "E302 expected 2 blank lines, found %d" % blank_lines
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238 if blank_lines > 2:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 return 0, "E303 too many blank lines (%d)" % blank_lines
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 def extraneous_whitespace(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244 Avoid extraneous whitespace in the following situations:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
245
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246 - Immediately inside parentheses, brackets or braces.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 - Immediately before a comma, semicolon, or colon.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 line = logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 for char in '([{':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 found = line.find(char + ' ')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254 return found + 1, "E201 whitespace after '%s'" % char
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 for char in '}])':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256 found = line.find(' ' + char)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
257 if found > -1 and line[found - 1] != ',':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258 return found, "E202 whitespace before '%s'" % char
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259 for char in ',;:':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
260 found = line.find(' ' + char)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
261 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 return found, "E203 whitespace before '%s'" % char
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
263
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
265 def missing_whitespace(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
266 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
267 JCR: Each comma, semicolon or colon should be followed by whitespace.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
269 line = logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
270 for index in range(len(line) - 1):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271 char = line[index]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
272 if char in ',;:' and line[index + 1] != ' ':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273 before = line[:index]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
274 if char == ':' and before.count('[') > before.count(']'):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
275 continue # Slice syntax, no space required
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 return index, "E231 missing whitespace after '%s'" % char
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
277
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279 def indentation(logical_line, previous_logical, indent_char,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
280 indent_level, previous_indent_level):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
282 Use 4 spaces per indentation level.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
283
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
284 For really old code that you don't want to mess up, you can continue to
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
285 use 8-space tabs.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
287 if indent_char == ' ' and indent_level % 4:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288 return 0, "E111 indentation is not a multiple of four"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
289 indent_expect = previous_logical.endswith(':')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290 if indent_expect and indent_level <= previous_indent_level:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
291 return 0, "E112 expected an indented block"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
292 if indent_level > previous_indent_level and not indent_expect:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293 return 0, "E113 unexpected indentation"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
294
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
295
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
296 def whitespace_before_parameters(logical_line, tokens):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
297 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
298 Avoid extraneous whitespace in the following situations:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
299
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300 - Immediately before the open parenthesis that starts the argument
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
301 list of a function call.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
302
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
303 - Immediately before the open parenthesis that starts an indexing or
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 slicing.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
305 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 prev_type = tokens[0][0]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
307 prev_text = tokens[0][1]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 prev_end = tokens[0][3]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
309 for index in range(1, len(tokens)):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
310 token_type, text, start, end, line = tokens[index]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
311 if (token_type == tokenize.OP and
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 text in '([' and
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
313 start != prev_end and
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
314 prev_type == tokenize.NAME and
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
315 (index < 2 or tokens[index - 2][1] != 'class') and
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
316 (not iskeyword(prev_text))):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
317 return prev_end, "E211 whitespace before '%s'" % text
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
318 prev_type = token_type
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
319 prev_text = text
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
320 prev_end = end
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
321
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
322
2446
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
323 def extra_whitespace_around_operator(logical_line):
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
324 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
325 Avoid extraneous whitespace in the following situations:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
326
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
327 - More than one space around an assignment (or other) operator to
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
328 align it with another.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
329 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
330 line = logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
331 for operator in operators:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
332 found = line.find(' ' + operator)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
333 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
334 return found, "E221 multiple spaces before operator"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
335 found = line.find(operator + ' ')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
336 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
337 return found, "E222 multiple spaces after operator"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
338 found = line.find('\t' + operator)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
339 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
340 return found, "E223 tab before operator"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
341 found = line.find(operator + '\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
342 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
343 return found, "E224 tab after operator"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
344
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
345
2446
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
346 def whitespace_around_operator(logical_line):
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
347 """
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
348 Have exactly 1 space left and right of the operator.
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
349 """
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
350 match = not_one_ws_around_operators_match(logical_line)
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
351 if match and not 'lambda' in logical_line:
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
352 return match.start(1), "E225 operators shall be surrounded by a single space on each side %s" % logical_line
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
353
70b1a82ec75b test_sourcecode: add pep8 test for 1 space on each side of an operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2445
diff changeset
354
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
355 def whitespace_around_comma(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
356 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
357 Avoid extraneous whitespace in the following situations:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
359 - More than one space around an assignment (or other) operator to
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
360 align it with another.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
361
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
362 JCR: This should also be applied around comma etc.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
363 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
364 line = logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
365 for separator in ',;:':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
366 found = line.find(separator + ' ')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
367 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
368 return found + 1, "E241 multiple spaces after '%s'" % separator
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
369 found = line.find(separator + '\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
370 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
371 return found + 1, "E242 tab after '%s'" % separator
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
372
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
373
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
374 def imports_on_separate_lines(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
375 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
376 Imports should usually be on separate lines.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
377 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
378 line = logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
379 if line.startswith('import '):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
380 found = line.find(',')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
381 if found > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
382 return found, "E401 multiple imports on one line"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
383
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
384
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
385 def compound_statements(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
386 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
387 Compound statements (multiple statements on the same line) are
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
388 generally discouraged.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
389 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
390 line = logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
391 found = line.find(':')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
392 if -1 < found < len(line) - 1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
393 before = line[:found]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
394 if (before.count('{') <= before.count('}') and # {'a': 1} (dict)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
395 before.count('[') <= before.count(']') and # [1:2] (slice)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
396 not re.search(r'\blambda\b', before)): # lambda x: x
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
397 return found, "E701 multiple statements on one line (colon)"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
398 found = line.find(';')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
399 if -1 < found:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
400 return found, "E702 multiple statements on one line (semicolon)"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
401
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
402
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403 def python_3000_has_key(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
404 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 The {}.has_key() method will be removed in the future version of
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
406 Python. Use the 'in' operation instead, like:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
407 d = {"a": 1, "b": 2}
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
408 if "b" in d:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
409 print d["b"]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
410 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
411 pos = logical_line.find('.has_key(')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
412 if pos > -1:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413 return pos, "W601 .has_key() is deprecated, use 'in'"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
414
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
415
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
416 def python_3000_raise_comma(logical_line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
417 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
418 When raising an exception, use "raise ValueError('message')"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
419 instead of the older form "raise ValueError, 'message'".
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
420
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 The paren-using form is preferred because when the exception arguments
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
422 are long or include string formatting, you don't need to use line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
423 continuation characters thanks to the containing parentheses. The older
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
424 form will be removed in Python 3000.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
425 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
426 match = raise_comma_match(logical_line)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
427 if match:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
428 return match.start(1), "W602 deprecated form of raising exception"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
429
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
430
2445
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
431 def dumb_equals_boolean(logical_line):
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
432 """
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
433 Using "if x == True:" or "if x == False:" is wrong in any case:
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
434
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
435 First if you already have a boolean, you don't need to compare it to
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
436 another boolean. Just use "if x:" or "if not x:".
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
437
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
438 Second, even if you have some sort of "tristate logic", not only using
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
439 True/False, but other values, then you want to use "if x is True:" or
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
440 "if x is False:" because there is exactly one True and one False object.
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
441 """
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
442 match = equals_boolean_search(logical_line)
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
443 if match:
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
444 return match.start(1), "E798 don't use 'x == <boolean>', but just 'x' or 'not x' or 'x is <boolean>'"
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
445
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
446
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
447 def dumb_equals_None(logical_line):
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
448 """
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
449 Using "if x == None:" is wrong in any case:
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
450
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
451 You either want to use "if x is None:" (there is only 1 None object) or -
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
452 in some simple cases - just "if not x:".
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
453 """
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
454 match = equals_None_search(logical_line)
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
455 if match:
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
456 return match.start(1), "E799 don't use 'x == None', but just 'x is None' or 'not x'"
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
457
2dc7a3be8ec9 test_sourcecode: check for some silly comparisons with None/True/False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2291
diff changeset
458
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
459 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
460 # Helper functions
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
461 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
462
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
463
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
464 def expand_indent(line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
465 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
466 Return the amount of indentation.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
467 Tabs are expanded to the next multiple of 8.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
468
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
469 >>> expand_indent(' ')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
470 4
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
471 >>> expand_indent('\\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
472 8
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473 >>> expand_indent(' \\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
474 8
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
475 >>> expand_indent(' \\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476 8
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
477 >>> expand_indent(' \\t')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
478 16
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
479 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
480 result = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
481 for char in line:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
482 if char == '\t':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
483 result = result / 8 * 8 + 8
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
484 elif char == ' ':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
485 result += 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
486 else:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
487 break
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
488 return result
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
489
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
490
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
491 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
492 # Framework to run all checks
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
493 ##############################################################################
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
496 def message(text):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
497 """Print a message."""
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
498 # print >> sys.stderr, options.prog + ': ' + text
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
499 # print >> sys.stderr, text
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
500 print text
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
501
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
502
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
503 def find_checks(argument_name):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
504 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505 Find all globally visible functions where the first argument name
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
506 starts with argument_name.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
507 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
508 checks = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
509 function_type = type(find_checks)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
510 for name, function in globals().iteritems():
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
511 if type(function) is function_type:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
512 args = inspect.getargspec(function)[0]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
513 if len(args) >= 1 and args[0].startswith(argument_name):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
514 checks.append((name, function, args))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
515 checks.sort()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
516 return checks
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
517
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
518
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
519 def mute_string(text):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
520 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
521 Replace contents with 'xxx' to prevent syntax matching.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
522
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
523 >>> mute_string('"abc"')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
524 '"xxx"'
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
525 >>> mute_string("'''abc'''")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
526 "'''xxx'''"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
527 >>> mute_string("r'abc'")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
528 "r'xxx'"
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
529 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
530 start = 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
531 end = len(text) - 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
532 # String modifiers (e.g. u or r)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
533 if text.endswith('"'):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
534 start += text.index('"')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
535 elif text.endswith("'"):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
536 start += text.index("'")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
537 # Triple quotes
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
538 if text.endswith('"""') or text.endswith("'''"):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
539 start += 2
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
540 end -= 2
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
541 return text[:start] + 'x' * (end - start) + text[end:]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
542
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
543
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
544 class Checker:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
545 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
546 Load a Python source file, tokenize it, check coding style.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
547 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
548
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
549 def __init__(self, filename):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
550 self.filename = filename
2291
c5d01f74189a test_sourcecode: use binary mode, so we can detect CRLF line ends on win32 platform, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2288
diff changeset
551 self.lines = file(filename, 'rb').readlines()
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
552 self.physical_checks = find_checks('physical_line')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
553 self.logical_checks = find_checks('logical_line')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
554 options.counters['physical lines'] = \
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
555 options.counters.get('physical lines', 0) + len(self.lines)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
556
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
557 def readline(self):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
558 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
559 Get the next line from the input buffer.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
560 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
561 self.line_number += 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
562 if self.line_number > len(self.lines):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
563 return ''
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
564 return self.lines[self.line_number - 1]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
565
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
566 def readline_check_physical(self):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
567 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
568 Check and return the next physical line. This method can be
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
569 used to feed tokenize.generate_tokens.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
570 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
571 line = self.readline()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
572 if line:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
573 self.check_physical(line)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
574 return line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
575
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
576 def run_check(self, check, argument_names):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
577 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
578 Run a check plugin.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
579 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
580 arguments = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
581 for name in argument_names:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
582 arguments.append(getattr(self, name))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
583 return check(*arguments)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
584
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
585 def check_physical(self, line):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
586 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
587 Run all physical checks on a raw input line.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
588 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
589 self.physical_line = line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
590 if self.indent_char is None and len(line) and line[0] in ' \t':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
591 self.indent_char = line[0]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
592 for name, check, argument_names in self.physical_checks:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
593 result = self.run_check(check, argument_names)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
594 if result is not None:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
595 offset, text = result
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
596 self.report_error(self.line_number, offset, text, check)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
597
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
598 def build_tokens_line(self):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
599 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
600 Build a logical line from tokens.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
601 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
602 self.mapping = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
603 logical = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
604 length = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
605 previous = None
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
606 for token in self.tokens:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
607 token_type, text = token[0:2]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
608 if token_type in (tokenize.COMMENT, tokenize.NL,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
609 tokenize.INDENT, tokenize.DEDENT,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
610 tokenize.NEWLINE):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
611 continue
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
612 if token_type == tokenize.STRING:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
613 text = mute_string(text)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
614 if previous:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
615 end_line, end = previous[3]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
616 start_line, start = token[2]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
617 if end_line != start_line: # different row
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
618 if self.lines[end_line - 1][end - 1] not in '{[(':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
619 logical.append(' ')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
620 length += 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
621 elif end != start: # different column
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
622 fill = self.lines[end_line - 1][end:start]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
623 logical.append(fill)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
624 length += len(fill)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
625 self.mapping.append((length, token))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
626 logical.append(text)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
627 length += len(text)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
628 previous = token
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
629 self.logical_line = ''.join(logical)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
630 assert self.logical_line.lstrip() == self.logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
631 assert self.logical_line.rstrip() == self.logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
632
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
633 def check_logical(self):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
634 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
635 Build a line from tokens and run all logical checks on it.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
636 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
637 options.counters['logical lines'] = \
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
638 options.counters.get('logical lines', 0) + 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
639 self.build_tokens_line()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
640 first_line = self.lines[self.mapping[0][1][2][0] - 1]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
641 indent = first_line[:self.mapping[0][1][2][1]]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
642 self.previous_indent_level = self.indent_level
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
643 self.indent_level = expand_indent(indent)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
644 if options.verbose >= 2:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
645 print self.logical_line[:80].rstrip()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
646 for name, check, argument_names in self.logical_checks:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
647 if options.verbose >= 3:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
648 print ' ', name
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
649 result = self.run_check(check, argument_names)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
650 if result is not None:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
651 offset, text = result
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
652 if type(offset) is tuple:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
653 original_number, original_offset = offset
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
654 else:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
655 for token_offset, token in self.mapping:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
656 if offset >= token_offset:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
657 original_number = token[2][0]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
658 original_offset = (token[2][1]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
659 + offset - token_offset)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
660 self.report_error(original_number, original_offset,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
661 text, check)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
662 self.previous_logical = self.logical_line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
663
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
664 def check_all(self):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
665 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
666 Run all checks on the input file.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
667 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
668 self.file_errors = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
669 self.line_number = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
670 self.indent_char = None
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
671 self.indent_level = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
672 self.previous_logical = ''
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
673 self.blank_lines = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
674 self.tokens = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
675 parens = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
676 for token in tokenize.generate_tokens(self.readline_check_physical):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
677 # print tokenize.tok_name[token[0]], repr(token)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
678 self.tokens.append(token)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
679 token_type, text = token[0:2]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
680 if token_type == tokenize.OP and text in '([{':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
681 parens += 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
682 if token_type == tokenize.OP and text in '}])':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
683 parens -= 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
684 if token_type == tokenize.NEWLINE and not parens:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
685 self.check_logical()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
686 self.blank_lines = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
687 self.tokens = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
688 if token_type == tokenize.NL and not parens:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
689 self.blank_lines += 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
690 self.tokens = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
691 if token_type == tokenize.COMMENT:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
692 self.blank_lines = 0
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
693 return self.file_errors
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
694
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
695 def report_error(self, line_number, offset, text, check):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
696 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
697 Report an error, according to options.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
698 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
699 if options.quiet == 1 and not self.file_errors:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
700 message(self.filename)
2283
959d0815e149 pep8: don't count stuff we ignore, added comments about pep8 test usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2281
diff changeset
701 code = text[:4]
959d0815e149 pep8: don't count stuff we ignore, added comments about pep8 test usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2281
diff changeset
702 if ignore_code(code):
959d0815e149 pep8: don't count stuff we ignore, added comments about pep8 test usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2281
diff changeset
703 return
2281
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
704 self.file_errors += 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
705 options.counters[code] = options.counters.get(code, 0) + 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
706 options.messages[code] = text[5:]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
707 if options.quiet:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
708 return
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
709 if options.testsuite:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
710 base = os.path.basename(self.filename)[:4]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
711 if base == code:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
712 return
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
713 if base[0] == 'E' and code[0] == 'W':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
714 return
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
715 if options.counters[code] == 1 or options.repeat:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
716 message("%s:%s:%d: %s" %
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
717 (self.filename, line_number, offset + 1, text))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
718 if options.show_source:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
719 line = self.lines[line_number - 1]
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
720 message(line.rstrip())
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
721 message(' ' * offset + '^')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
722 if options.show_pep8:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
723 message(check.__doc__.lstrip('\n').rstrip())
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
724
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
725
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
726 def input_file(filename):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
727 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
728 Run all checks on a Python source file.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
729 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
730 if excluded(filename) or not filename_match(filename):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
731 return {}
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
732 if options.verbose:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
733 message('checking ' + filename)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
734 options.counters['files'] = options.counters.get('files', 0) + 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
735 errors = Checker(filename).check_all()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
736 if options.testsuite and not errors:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
737 message("%s: %s" % (filename, "no errors found"))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
738
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
739
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
740 def input_dir(dirname):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
741 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
742 Check all Python source files in this directory and all subdirectories.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
743 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
744 dirname = dirname.rstrip('/')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
745 if excluded(dirname):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
746 return
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
747 for root, dirs, files in os.walk(dirname):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
748 if options.verbose:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
749 message('directory ' + root)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
750 options.counters['directories'] = \
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
751 options.counters.get('directories', 0) + 1
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
752 dirs.sort()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
753 for subdir in dirs:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
754 if excluded(subdir):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
755 dirs.remove(subdir)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
756 files.sort()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
757 for filename in files:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
758 input_file(os.path.join(root, filename))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
759
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
760
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
761 def excluded(filename):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
762 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
763 Check if options.exclude contains a pattern that matches filename.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
764 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
765 basename = os.path.basename(filename)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
766 for pattern in options.exclude:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
767 if fnmatch(basename, pattern):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
768 # print basename, 'excluded because it matches', pattern
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
769 return True
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
770
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
771
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
772 def filename_match(filename):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
773 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
774 Check if options.filename contains a pattern that matches filename.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
775 If options.filename is unspecified, this always returns True.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
776 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
777 if not options.filename:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
778 return True
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
779 for pattern in options.filename:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
780 if fnmatch(filename, pattern):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
781 return True
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
782
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
783
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
784 def ignore_code(code):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
785 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
786 Check if options.ignore contains a prefix of the error code.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
787 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
788 for ignore in options.ignore:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
789 if code.startswith(ignore):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
790 return True
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
791
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
792
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
793 def get_error_statistics():
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
794 """Get error statistics."""
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
795 return get_statistics("E")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
796
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
797
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
798 def get_warning_statistics():
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
799 """Get warning statistics."""
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
800 return get_statistics("W")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
801
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
802
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
803 def get_statistics(prefix=''):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
804 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
805 Get statistics for message codes that start with the prefix.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
806
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
807 prefix='' matches all errors and warnings
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
808 prefix='E' matches all errors
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
809 prefix='W' matches all warnings
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
810 prefix='E4' matches all errors that have to do with imports
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
811 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
812 stats = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
813 keys = options.messages.keys()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
814 keys.sort()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
815 for key in keys:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
816 if key.startswith(prefix):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
817 stats.append('%-7s %s %s' %
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
818 (options.counters[key], key, options.messages[key]))
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
819 return stats
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
820
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
821
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
822 def print_statistics(prefix=''):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
823 """Print overall statistics (number of errors and warnings)."""
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
824 for line in get_statistics(prefix):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
825 print line
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
826
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
827
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
828 def print_benchmark(elapsed):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
829 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
830 Print benchmark numbers.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
831 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
832 print '%-7.2f %s' % (elapsed, 'seconds elapsed')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
833 keys = ['directories', 'files',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
834 'logical lines', 'physical lines']
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
835 for key in keys:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
836 if key in options.counters:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
837 print '%-7d %s per second (%d total)' % (
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
838 options.counters[key] / elapsed, key,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
839 options.counters[key])
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
840
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
841
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
842 def process_options(arglist=None):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
843 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
844 Process options passed either via arglist or via command line args.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
845 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
846 global options, args
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
847 usage = "%prog [options] input ..."
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
848 parser = OptionParser(usage)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
849 parser.add_option('-v', '--verbose', default=0, action='count',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
850 help="print status messages, or debug with -vv")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
851 parser.add_option('-q', '--quiet', default=0, action='count',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
852 help="report only file names, or nothing with -qq")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
853 parser.add_option('--exclude', metavar='patterns', default=default_exclude,
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
854 help="skip matches (default %s)" % default_exclude)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
855 parser.add_option('--filename', metavar='patterns',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
856 help="only check matching files (e.g. *.py)")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
857 parser.add_option('--ignore', metavar='errors', default='',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
858 help="skip errors and warnings (e.g. E4,W)")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
859 parser.add_option('--repeat', action='store_true',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
860 help="show all occurrences of the same error")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
861 parser.add_option('--show-source', action='store_true',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
862 help="show source code for each error")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
863 parser.add_option('--show-pep8', action='store_true',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
864 help="show text of PEP 8 for each error")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
865 parser.add_option('--statistics', action='store_true',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
866 help="count errors and warnings")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
867 parser.add_option('--benchmark', action='store_true',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
868 help="measure processing speed")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
869 parser.add_option('--testsuite', metavar='dir',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
870 help="run regression tests from dir")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
871 parser.add_option('--doctest', action='store_true',
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
872 help="run doctest on myself")
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
873 options, args = parser.parse_args(arglist)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
874 if options.testsuite:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
875 args.append(options.testsuite)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
876 if len(args) == 0:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
877 parser.error('input not specified')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
878 options.prog = os.path.basename(sys.argv[0])
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
879 options.exclude = options.exclude.split(',')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
880 for index in range(len(options.exclude)):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
881 options.exclude[index] = options.exclude[index].rstrip('/')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
882 if options.filename:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
883 options.filename = options.filename.split(',')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
884 if options.ignore:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
885 options.ignore = options.ignore.split(',')
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
886 else:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
887 options.ignore = []
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
888 options.counters = {}
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
889 options.messages = {}
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
890
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
891 return options, args
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
892
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
893
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
894 def _main():
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
895 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
896 Parse options and run checks on Python source.
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
897 """
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
898 options, args = process_options()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
899 if options.doctest:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
900 import doctest
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
901 return doctest.testmod()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
902 start_time = time.time()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
903 for path in args:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
904 if os.path.isdir(path):
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
905 input_dir(path)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
906 else:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
907 input_file(path)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
908 elapsed = time.time() - start_time
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
909 if options.statistics:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
910 print_statistics()
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
911 if options.benchmark:
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
912 print_benchmark(elapsed)
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
913
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
914
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
915 if __name__ == '__main__':
a6a4eaa948aa test_sourcecode: added PEP8 checker
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
916 _main()