Adapted pylint disable messages to pylint 0.11.
[joel/kofoto.git] / check.py
1 #! /usr/bin/env python
2
3 import os
4 import sys
5 from optparse import OptionParser
6 import warnings
7 from pylint import lint
8
9 def disable_message(arguments, message_id):
10     arguments.append("--disable-msg=%s" % message_id)
11
12 ######################################################################
13
14 option_parser = OptionParser()
15 option_parser.add_option(
16     "--all",
17     action="store_true",
18     help="perform all checks",
19     default=False)
20 option_parser.add_option(
21     "--all-complexity",
22     action="store_true",
23     help="perform all complexity checks",
24     default=False)
25 options, args = option_parser.parse_args(sys.argv[1:])
26
27 topdir = os.path.dirname(sys.argv[0])
28
29 sys.path.insert(0, os.path.join(topdir, "src/packages"))
30 if len(args) > 0:
31     modules = args
32 else:
33     modules = ["kofoto"]
34
35 normally_disabled_tests = [
36     "C0103", # "Invalid name"
37     "C0111", # "Missing docstring"
38     "I0011", # "Locally disabling ..."
39     "R0801", # "Similar lines ..."
40     "W0142", # "Used * or ** magic."
41     "W0511", # "TODO ..."
42     "W0704", # "Except doesn't do anything."
43 ]
44
45 normally_disabled_complexity_tests = [
46     "C0302", # "Too many lines in module"
47     "R0901", # "Too many parent classes."
48     "R0902", # "Too many instance attributes."
49     "R0903", # "Not enough public methods."
50     "R0904", # "Too many public methods."
51     "R0911", # "Too many return statement."
52     "R0912", # "Too many branches."
53     "R0913", # "Too many arguments."
54     "R0914", # "Too many local variables."
55     "R0915", # "Too many statements."
56     "C0301", # "Line too long."
57 ]
58
59 rc_file_location = os.path.join(topdir, "misc/pylintrc")
60 flags = ["--rcfile", rc_file_location]
61 if not options.all:
62     for x in normally_disabled_tests:
63         disable_message(flags, x)
64     if not options.all_complexity:
65         for x in normally_disabled_complexity_tests:
66             disable_message(flags, x)
67
68 lint.Run(flags + modules)