-
-
Notifications
You must be signed in to change notification settings - Fork 761
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (56 loc) · 1.86 KB
/
main.py
File metadata and controls
83 lines (56 loc) · 1.86 KB
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
76
77
78
79
80
81
82
83
""" Pylama's shell support. """
from __future__ import absolute_import, with_statement
import sys
from os import walk, path as op
from .config import parse_options, CURDIR, setup_logger
from .core import LOGGER
DEFAULT_COMPLEXITY = 10
def shell(args=None, error=True):
""" Endpoint for console.
Parse a command arguments, configuration files and run a checkers.
:return list: list of errors
:raise SystemExit:
"""
if args is None:
args = sys.argv[1:]
options = parse_options(args)
setup_logger(options)
LOGGER.info(options)
# Install VSC hook
if options.hook:
from .hook import install_hook
return install_hook(options.path)
paths = [options.path]
if op.isdir(options.path):
paths = []
for root, _, files in walk(options.path):
paths += [
op.relpath(op.join(root, f), CURDIR)
for f in files
if any(l.allow(f) for _, l in options.linters)]
return check_files(paths, options, error=error)
def check_files(paths, options, rootpath=None, error=True):
""" Check files.
:return list: list of errors
:raise SystemExit:
"""
from .tasks import async_check_files
if rootpath is None:
rootpath = CURDIR
pattern = "%(rel)s:%(lnum)s:%(col)s: %(text)s"
if options.format == 'pylint':
pattern = "%(rel)s:%(lnum)s: [%(type)s] %(text)s"
work_paths = []
for path in paths:
if options.skip and any(p.match(path) for p in options.skip):
LOGGER.info('Skip path: %s', path)
continue
work_paths.append(path)
errors = async_check_files(work_paths, options, rootpath=rootpath)
for er in errors:
LOGGER.warning(pattern, er)
if error:
sys.exit(int(bool(errors)))
return errors
if __name__ == '__main__':
shell()