aboutsummaryrefslogtreecommitdiff
blob: 183e24be7bac9c445fe2666a00da11ed6fb4b74b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

"""Run pylint with the right settings."""

import os
import sys


def find_all_modules(source_root):
    """Locate all python modules in the tree for scanning"""
    ret = []

    for root, _dirs, files in os.walk(source_root, topdown=False):
        # Add all of the .py modules in the tree.
        ret += [os.path.join(root, x) for x in files if x.endswith('.py')]

    # Add the main scripts that don't end in .py.
    ret += [os.path.join(source_root, 'bin', x)
            for x in ('catalyst', 'pylint')]

    return ret


def main(argv):
    """The main entry point"""
    source_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

    if not argv:
        argv = find_all_modules(source_root)

    pympath = source_root
    pythonpath = os.environ.get('PYTHONPATH')
    if pythonpath is None:
        pythonpath = pympath
    else:
        pythonpath = pympath + ':' + pythonpath
    os.environ['PYTHONPATH'] = pythonpath

    pylintrc = os.path.join(source_root, '.pylintrc')
    cmd = ['pylint', '--rcfile', pylintrc]
    os.execvp(cmd[0], cmd + argv)


if __name__ == '__main__':
    main(sys.argv[1:])