-
Notifications
You must be signed in to change notification settings - Fork 171
/
__init__.py
94 lines (75 loc) · 2.63 KB
/
__init__.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from __future__ import absolute_import
from frosted.api import check_path
from prospector.message import Location, Message
from prospector.tools.base import ToolBase
__all__ = (
'FrostedTool',
)
class ProspectorReporter(object):
def __init__(self, ignore=None):
self._messages = []
self.ignore = ignore or ()
# pylint: disable=R0913
def record_message(
self,
filename=None,
line=None,
character=None,
code=None,
message=None):
if code in self.ignore:
return
location = Location(
path=filename,
module=None,
function=None,
line=line,
character=character,
)
message = Message(
source='frosted',
code=code,
location=location,
message=message,
)
self._messages.append(message)
def unexpected_error(self, filename, msg):
self.record_message(
filename=filename,
code='U999',
message=msg,
)
def flake(self, message):
filename, _, msg = message.message.split(':', 2)
self.record_message(
filename=filename,
line=message.lineno,
character=(message.col + 1),
code=message.type.error_code,
message=msg,
)
def get_messages(self):
return self._messages
class FrostedTool(ToolBase):
def __init__(self, *args, **kwargs):
super(FrostedTool, self).__init__(*args, **kwargs)
self.ignore_codes = ()
def configure(self, prospector_config, _):
self.ignore_codes = prospector_config.get_disabled_messages('frosted')
return None
def run(self, found_files):
reporter = ProspectorReporter(ignore=self.ignore_codes)
for filepath in found_files.iter_module_paths():
# Frosted cannot handle non-utf-8 encoded files at the moment -
# see https://github.com/timothycrosley/frosted/issues/53
# Therefore (since pyflakes overlaps heavily and does not have the same
# problem) we will simply suppress that error. If you do get it working
# correctly, you only end up with a "CannotDecodeFile" error anyway which
# is not useful to the user of prospector, nor is it actually a problem
# of the file but rather of frosted.
try:
check_path(filepath, reporter)
except UnicodeDecodeError:
# pylint:disable=pointless-except
pass
return reporter.get_messages()