11
11
12
12
"""This module exports the Flake8 plugin linter class."""
13
13
14
- import os
15
- from SublimeLinter .lint import persist , PythonLinter
14
+ from SublimeLinter .lint import PythonLinter
16
15
17
16
18
17
class Flake8 (PythonLinter ):
@@ -56,83 +55,11 @@ class Flake8(PythonLinter):
56
55
'--max-line-length=' : None ,
57
56
'--max-complexity=' : - 1 ,
58
57
'--jobs=' : '1' ,
59
- '--show-code=' : False
58
+ 'show-code' : False ,
59
+ 'executable' : ''
60
60
}
61
- inline_settings = ('max-line-length' , 'max-complexity' , 'show_code' )
61
+ inline_settings = ('max-line-length' , 'max-complexity' )
62
62
inline_overrides = ('select' , 'ignore' , 'builtins' )
63
- module = 'flake8.engine'
64
- check_version = True
65
-
66
- # Internal
67
- report = None
68
- show_code = False
69
- pyflakes_checker_module = None
70
- pyflakes_checker_class = None
71
-
72
- @classmethod
73
- def initialize (cls ):
74
- """Initialize the class after plugin load."""
75
-
76
- super ().initialize ()
77
-
78
- if cls .module is None :
79
- return
80
-
81
- # This is tricky. Unfortunately pyflakes chooses to store
82
- # builtins in a class variable and union that with the builtins option
83
- # on every execution. This results in the builtins never being removed.
84
- # To fix that, we get a reference to the pyflakes.checker module and
85
- # pyflakes.checker.Checker class used by flake8. We can then reset
86
- # the Checker.builtIns class variable on each execution.
87
-
88
- try :
89
- from pkg_resources import iter_entry_points
90
- except ImportError :
91
- persist .printf ('WARNING: {} could not import pkg_resources.iter_entry_points' .format (cls .name ))
92
- else :
93
- for entry in iter_entry_points ('flake8.extension' ):
94
- check = entry .load ()
95
-
96
- if check .name == 'pyflakes' :
97
- from pyflakes import checker
98
- cls .pyflakes_checker_module = checker
99
- cls .pyflakes_checker_class = check
100
- break
101
-
102
- def check (self , code , filename ):
103
- """Run flake8 on code and return the output."""
104
-
105
- options = {
106
- 'reporter' : self .get_report (),
107
- 'jobs' : '1' # No multiprocessing
108
- }
109
-
110
- type_map = {
111
- 'select' : [],
112
- 'ignore' : [],
113
- 'builtins' : '' ,
114
- 'max-line-length' : 0 ,
115
- 'max-complexity' : 0 ,
116
- 'show-code' : False
117
- }
118
-
119
- self .build_options (options , type_map , transform = lambda s : s .replace ('-' , '_' ))
120
- self .show_code = options .pop ('show_code' , False )
121
-
122
- if persist .debug_mode ():
123
- persist .printf ('{} options: {}' .format (self .name , options ))
124
-
125
- if self .pyflakes_checker_class is not None :
126
- # Reset the builtins to the initial value used by pyflakes.
127
- builtins = set (self .pyflakes_checker_module .builtin_vars ).union (self .pyflakes_checker_module ._MAGIC_GLOBALS )
128
- self .pyflakes_checker_class .builtIns = builtins
129
-
130
- linter = self .module .get_style_guide (** options )
131
-
132
- return linter .input_file (
133
- filename = os .path .basename (filename ),
134
- lines = code .splitlines (keepends = True )
135
- )
136
63
137
64
def split_match (self , match ):
138
65
"""
@@ -148,34 +75,17 @@ def split_match(self, match):
148
75
if near :
149
76
col = None
150
77
151
- if self .show_code :
78
+ if self .get_view_settings (). get ( 'show-code' ) :
152
79
message = ' ' .join ([error or warning or '' , message ])
153
80
return match , line , col , error , warning , message , near
154
81
155
- def get_report (self ):
156
- """Return the Report class for use by flake8."""
157
- if self .report is None :
158
- from pep8 import StandardReport
159
-
160
- class Report (StandardReport ):
161
- """Provides a report in the form of a single multiline string, without printing."""
82
+ def build_cmd (self , cmd = None ):
83
+ """Return a tuple with the command line to execute."""
162
84
163
- def get_file_results (self ):
164
- """Collect and return the results for this file."""
165
- self ._deferred_print .sort ()
166
- results = ''
167
-
168
- for line_number , offset , code , text , doc in self ._deferred_print :
169
- results += '{path}:{row}:{col}: {code} {text}\n ' .format_map ({
170
- 'path' : self .filename ,
171
- 'row' : self .line_offset + line_number ,
172
- 'col' : offset + 1 ,
173
- 'code' : code ,
174
- 'text' : text
175
- })
176
-
177
- return results
178
-
179
- self .__class__ .report = Report
180
-
181
- return self .report
85
+ executable = self .get_view_settings ().get ('executable' , None )
86
+ if executable :
87
+ args = (cmd or self .cmd )[1 :]
88
+ cmd = (executable , ) + args
89
+ return self .insert_args (cmd )
90
+ else :
91
+ return super ().build_cmd (cmd )
0 commit comments