4 # written by Sylvain Rouquette, 2011
12 To add the pep8 tool to the waf file:
13 $ ./waf-light --tools=compat15,pep8
14 or, if you have waf >= 1.6.2
15 $ ./waf update --files=pep8
18 Then add this to your wscript:
20 [at]extension('.py', 'wscript')
21 def run_pep8(self, node):
22 self.create_task('Pep8', node)
27 from waflib import Task, Options
29 pep8 = __import__('pep8')
32 class Pep8(Task.Task):
34 lock = threading.Lock()
36 def check_options(self):
39 pep8.options = Options.options
40 pep8.options.prog = 'pep8'
41 excl = pep8.options.exclude.split(',')
42 pep8.options.exclude = [s.rstrip('/') for s in excl]
43 if pep8.options.filename:
44 pep8.options.filename = pep8.options.filename.split(',')
45 if pep8.options.select:
46 pep8.options.select = pep8.options.select.split(',')
48 pep8.options.select = []
49 if pep8.options.ignore:
50 pep8.options.ignore = pep8.options.ignore.split(',')
51 elif pep8.options.select:
52 # Ignore all checks which are not explicitly selected
53 pep8.options.ignore = ['']
54 elif pep8.options.testsuite or pep8.options.doctest:
55 # For doctest and testsuite, all checks are required
56 pep8.options.ignore = []
58 # The default choice: ignore controversial checks
59 pep8.options.ignore = pep8.DEFAULT_IGNORE.split(',')
60 pep8.options.physical_checks = pep8.find_checks('physical_line')
61 pep8.options.logical_checks = pep8.find_checks('logical_line')
62 pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
63 pep8.options.messages = {}
68 pep8.input_file(self.inputs[0].abspath())
69 return 0 if not pep8.get_count() else -1
73 opt.add_option('-q', '--quiet', default=0, action='count',
74 help="report only file names, or nothing with -qq")
75 opt.add_option('-r', '--repeat', action='store_true',
76 help="show all occurrences of the same error")
77 opt.add_option('--exclude', metavar='patterns',
78 default=pep8.DEFAULT_EXCLUDE,
79 help="exclude files or directories which match these "
80 "comma separated patterns (default: %s)" %
83 opt.add_option('--filename', metavar='patterns', default='*.py',
84 help="when parsing directories, only check filenames "
85 "matching these comma separated patterns (default: "
87 opt.add_option('--select', metavar='errors', default='',
88 help="select errors and warnings (e.g. E,W6)")
89 opt.add_option('--ignore', metavar='errors', default='',
90 help="skip errors and warnings (e.g. E4,W)")
91 opt.add_option('--show-source', action='store_true',
92 help="show source code for each error")
93 opt.add_option('--show-pep8', action='store_true',
94 help="show text of PEP 8 for each error")
95 opt.add_option('--statistics', action='store_true',
96 help="count errors and warnings")
97 opt.add_option('--count', action='store_true',
98 help="print total number of errors and warnings "
99 "to standard error and set exit code to 1 if "
101 opt.add_option('--benchmark', action='store_true',
102 help="measure processing speed")
103 opt.add_option('--testsuite', metavar='dir',
104 help="run regression tests from dir")
105 opt.add_option('--doctest', action='store_true',
106 help="run doctest on myself")