-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_pylint.py
executable file
·75 lines (57 loc) · 2.08 KB
/
run_pylint.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# Copyright (c) 2018 The ungoogled-chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Run Pylint over any module"""
import argparse
import os
import shutil
from pathlib import Path
from pylint import epylint as lint
def run_pylint(modulepath, pylint_options):
"""Runs Pylint. Returns a boolean indicating success"""
pylint_stats = Path('/run/user/{}/pylint_stats'.format(os.getuid()))
if not pylint_stats.parent.is_dir(): #pylint: disable=no-member
pylint_stats = Path('/run/shm/pylint_stats')
os.environ['PYLINTHOME'] = str(pylint_stats)
result = lint.lint(
filename=str(modulepath),
options=pylint_options,
)
if pylint_stats.is_dir():
shutil.rmtree(str(pylint_stats))
if result != 0:
print('WARNING: {}() returned non-zero result: {}'.format(
'.'.join((lint.lint.__module__, lint.lint.__name__)), result))
return False
return True
def main():
"""CLI entrypoint"""
parser = argparse.ArgumentParser(description='Run Pylint over an arbitrary module')
parser.add_argument('--hide-fixme', action='store_true', help='Hide "fixme" Pylint warnings.')
parser.add_argument(
'--show-locally-disabled',
action='store_true',
help='Show "locally-disabled" Pylint warnings.')
parser.add_argument('modulepath', type=Path, help='Path to the module to check')
args = parser.parse_args()
if not args.modulepath.exists():
print('ERROR: Module path "{}" does not exist'.format(args.modulepath))
exit(1)
disables = [
'wrong-import-position',
'bad-continuation',
]
if args.hide_fixme:
disables.append('fixme')
if not args.show_locally_disabled:
disables.append('locally-disabled')
pylint_options = [
'--disable={}'.format(','.join(disables)),
'--jobs=4',
]
if not run_pylint(args.modulepath, pylint_options):
exit(1)
exit(0)
if __name__ == '__main__':
main()