Failed Conditions
Pull Request — master (#1109)
by Abdeali
01:46
created

bears.python.PyLintBear.run()   B

Complexity

Conditions 4

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 25
rs 8.5806
1
import sys
2
import re
3
4
from coalib.bearlib.abstractions.Lint import Lint
5
from coalib.bears.LocalBear import LocalBear
6
from coalib.settings.Setting import typed_list
7
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
8
9
10
# We omit this case in our tests for technical reasons
11
if sys.version_info < (3, 3):  # pragma: no cover
12
    raise ImportError("PyLint does not support python3 < 3.3")
13
14
15
class PyLintBear(LocalBear, Lint):
16
    executable = 'pylint'
17
    arguments = ('--reports=n --persistent=n --msg-template='
18
                 '"{line}.{column}|{C}: {msg_id} - {msg}"')
19
    output_regex = re.compile(r'(?P<line>\d+)\.(?P<column>\d+)'
20
                    r'\|(?P<severity>[WFECRI]): (?P<message>.*)')
21
22
    def _get_groupdict(self, match):
23
        groups = Lint._get_groupdict(self, match)
24
25
        if groups["severity"] in "FE":
26
            groups["severity"] = RESULT_SEVERITY.MAJOR
27
        elif groups["severity"] in "CRI":
28
            groups["severity"] = RESULT_SEVERITY.INFO
29
        else:
30
            groups["severity"] = RESULT_SEVERITY.NORMAL
31
32
        return groups
33
34
    def run(self,
35
            filename,
36
            file,
37
            pylint_disable: typed_list(str)=("fixme"),
38
            pylint_enable: typed_list(str)=None,
39
            pylint_cli_options: str=""):
40
        '''
41
        Checks the code with pylint. This will run pylint over each file
42
        separately.
43
44
        :param pylint_disable:     Disable the message, report, category or
45
                                   checker with the given id(s).
46
        :param pylint_enable:      Enable the message, report, category or
47
                                   checker with the given id(s).
48
        :param pylint_cli_options: Any command line options you wish to be
49
                                   passed to pylint.
50
        '''
51
        if pylint_disable:
52
            self.arguments += " --disable=" + ",".join(pylint_disable)
53
        if pylint_enable:
54
            self.arguments += " --enable=" + ",".join(pylint_enable)
55
        if pylint_cli_options:
56
            self.arguments += " " + pylint_cli_options
57
58
        return self.lint(filename)
59