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