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     "W0142", # "Used * or ** magic."
38     "W0704", # "Except doesn't do anything."
39 ]
40
41 normally_disabled_complexity_tests = [
42     "R0901", # "Too many parent classes."
43     "R0902", # "Too many instance attributes."
44     "R0903", # "Not enough public methods."
45     "R0904", # "Too many public methods."
46     "R0911", # "Too many return statement."
47     "R0912", # "Too many branches."
48     "R0913", # "Too many arguments."
49     "R0914", # "Too many local variables."
50     "R0915", # "Too many statements."
51     "W0302", # "Too many lines in module."
52     "C0301", # "Line too long."
53 ]
54
55 rc_file_location = os.path.join(topdir, "misc/pylintrc")
56 flags = ["--rcfile", rc_file_location]
57 if not options.all:
58     for x in normally_disabled_tests:
59         disable_message(flags, x)
60     if not options.all_complexity:
61         for x in normally_disabled_complexity_tests:
62             disable_message(flags, x)
63
64 lint.Run(flags + modules)