11
11
12
12
"""This module exports the PYCODESTYLE plugin linter class."""
13
13
14
- import os
15
14
16
- from SublimeLinter .lint import persist , PythonLinter
15
+ from SublimeLinter .lint import PythonLinter
17
16
18
17
19
18
class PYCODESTYLE (PythonLinter ):
20
19
"""Provides an interface to the pep8 python module/script."""
21
20
22
21
syntax = 'python'
23
- cmd = ('pycodestyle@python ' , '*' , '-' )
22
+ cmd = ('pycodestyle' , '*' , '-' )
24
23
version_args = '--version'
25
24
version_re = r'(?P<version>\d+\.\d+\.\d+)'
26
25
version_requirement = '>= 1.4.6'
@@ -31,89 +30,3 @@ class PYCODESTYLE(PythonLinter):
31
30
'--ignore=,' : '' ,
32
31
'--max-line-length=' : None
33
32
}
34
- module = 'pycodestyle'
35
- check_version = True
36
-
37
- # Internal
38
- report = None
39
-
40
- def check (self , code , filename ):
41
- """Run pycodestyle on code and return the output."""
42
- options = {
43
- 'reporter' : self .get_report ()
44
- }
45
-
46
- type_map = {
47
- 'select' : [],
48
- 'ignore' : [],
49
- 'max-line-length' : 0 ,
50
- 'max-complexity' : 0
51
- }
52
-
53
- self .build_options (options , type_map , transform = lambda s : s .replace ('-' , '_' ))
54
-
55
- final_options = options .copy ()
56
-
57
- # Try to read options from pycodestyle default configuration files (.pycodestyle, tox.ini).
58
- # If present, they will override the ones defined by Sublime Linter's config.
59
- try :
60
- # `onError` will be called by `process_options` when no pycodestyle configuration file is found.
61
- # Override needed to supress OptionParser.error() output in the default parser.
62
- def onError (msg ):
63
- pass
64
-
65
- from pycodestyle import process_options , get_parser
66
- parser = get_parser ()
67
- parser .error = onError
68
- pycodestyle_options , _ = process_options ([os .curdir ], True , True , parser = parser )
69
-
70
- if pycodestyle_options .config :
71
- pycodestyle_options = vars (pycodestyle_options )
72
- pycodestyle_options .pop ('reporter' , None )
73
- for opt_n , opt_v in pycodestyle_options .items ():
74
- if isinstance (final_options .get (opt_n , None ), list ):
75
- final_options [opt_n ] += opt_v
76
- else :
77
- final_options [opt_n ] = opt_v
78
- except SystemExit :
79
- # Catch and ignore parser.error() when no config files are found.
80
- pass
81
-
82
- if persist .debug_mode ():
83
- persist .printf ('{} ST options: {}' .format (self .name , options ))
84
- persist .printf ('{} options: {}' .format (self .name , final_options ))
85
-
86
- checker = self .module .StyleGuide (** final_options )
87
-
88
- return checker .input_file (
89
- filename = os .path .basename (filename ),
90
- lines = code .splitlines (keepends = True )
91
- )
92
-
93
- def get_report (self ):
94
- """Return the Report class for use by flake8."""
95
- if self .report is None :
96
- from pycodestyle import StandardReport
97
-
98
- class Report (StandardReport ):
99
- """Provides a report in the form of a single multiline string, without printing."""
100
-
101
- def get_file_results (self ):
102
- """Collect and return the results for this file."""
103
- self ._deferred_print .sort ()
104
- results = ''
105
-
106
- for line_number , offset , code , text , _ in self ._deferred_print :
107
- results += '{path}:{row}:{col}: {code} {text}\n ' .format_map ({
108
- 'path' : self .filename ,
109
- 'row' : self .line_offset + line_number ,
110
- 'col' : offset + 1 ,
111
- 'code' : code ,
112
- 'text' : text
113
- })
114
-
115
- return results
116
-
117
- self .__class__ .report = Report
118
-
119
- return self .report
0 commit comments