Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd610ccd

Browse files
committed
Update pylama to version 3.3.2
1 parent80dddfe commitd610ccd

File tree

15 files changed

+192
-108
lines changed

15 files changed

+192
-108
lines changed

‎pymode/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
defauto():
1010
""" Fix PEP8 erorrs in current buffer. """
11-
1211
from .autopep8importfix_file
1312

1413
classOptions(object):
@@ -30,7 +29,6 @@ class Options(object):
3029

3130
defget_documentation():
3231
""" Search documentation and append to current buffer. """
33-
3432
try:
3533
fromStringIOimportStringIO
3634
exceptImportError:

‎pymode/async.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Python-mode async support. """
2+
23
try:
34
fromQueueimportQueue
45
exceptImportError:

‎pymode/environment.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ class VimPymodeEnviroment(object):
1717
prefix='[Pymode]'
1818

1919
def__init__(self):
20+
""" Init VIM environment. """
2021
self.current=vim.current
2122
self.options=dict(encoding=vim.eval('&enc'))
2223
self.options['debug']=self.var('g:pymode_debug',True)
2324

2425
@property
2526
defcurdir(self):
2627
""" Return current working directory. """
27-
2828
returnself.var('getcwd()')
2929

3030
@property
3131
defcurbuf(self):
3232
""" Return current buffer. """
33-
3433
returnself.current.buffer
3534

3635
@property
@@ -45,7 +44,6 @@ def cursor(self):
4544
@property
4645
defsource(self):
4746
""" Return source of current buffer. """
48-
4947
return"\n".join(self.lines)
5048

5149
@property
@@ -66,7 +64,6 @@ def var(self, name, to_bool=False):
6664
:return vimobj:
6765
6866
"""
69-
7067
value=vim.eval(name)
7168

7269
ifto_bool:
@@ -82,7 +79,6 @@ def message(self, msg, history=False):
8279
:return: :None
8380
8481
"""
85-
8682
ifhistory:
8783
returnvim.command('echom "%s"'%str(msg))
8884

@@ -149,16 +145,14 @@ def error(self, msg):
149145

150146
defdebug(self,msg,*args):
151147
""" Print debug information. """
152-
153148
ifself.options.get('debug'):
154149
print("%s %s [%s]"% (
155150
int(time.time()),msg,', '.join([str(a)forainargs])))
156151

157152
defstop(self,value=None):
158153
""" Break Vim function. """
159-
160154
cmd='return'
161-
ifnotvalueisNone:
155+
ifvalueisnotNone:
162156
cmd+=' '+self.prepare_value(value)
163157
vim.command(cmd)
164158

@@ -168,7 +162,6 @@ def catch_exceptions(self, func):
168162
:return func:
169163
170164
"""
171-
172165
def_wrapper(*args,**kwargs):
173166
try:
174167
returnfunc(*args,**kwargs)
@@ -181,7 +174,6 @@ def _wrapper(*args, **kwargs):
181174

182175
defrun(self,name,*args):
183176
""" Run vim function. """
184-
185177
vim.command('call %s(%s)'% (name,", ".join([
186178
self.prepare_value(a)forainargs
187179
])))
@@ -198,7 +190,6 @@ def prepare_value(self, value, dumps=True):
198190
:return unicode string:
199191
200192
"""
201-
202193
ifdumps:
203194
value=json.dumps(value)
204195

@@ -229,12 +220,10 @@ def get_offset_params(self, cursor=None, base=""):
229220

230221
defgoto_line(self,line):
231222
""" Go to line. """
232-
233223
vim.command('normal %sggzz'%line)
234224

235225
defgoto_file(self,path,cmd='e',force=False):
236226
""" Function description. """
237-
238227
ifforceoros.path.abspath(path)!=self.curbuf.name:
239228
self.debug('read',path)
240229
vim.command("%s %s"% (cmd,path))

‎pymode/libs/pylama/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
"""
77

8-
__version__="3.2.0"
8+
__version__="3.3.2"
99
__project__="pylama"
1010
__author__="Kirill Klenov <horneds@gmail.com>"
1111
__license__="GNU LGPL"

‎pymode/libs/pylama/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def __init__(self, value=None):
3333
def__str__(self):
3434
returnstr(self.value)
3535

36-
__repr__=lambdas:"<_Default [%s]>"%s.value
36+
def__repr__(self):
37+
return"<_Default [%s]>"%self.value
3738

3839

3940
defsplit_csp_str(s):

‎pymode/libs/pylama/core.py

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
importre
77

88
importlogging
9+
fromcollectionsimportdefaultdict
910

1011
from .configimportprocess_value,LOGGER
1112
from .lint.extensionsimportLINTERS
13+
from .errorsimportDUPLICATES,Error
1214

1315

1416
#: The skip pattern
@@ -20,18 +22,24 @@
2022
re.I|re.M)
2123

2224

23-
defrun(path,code=None,options=None):
25+
defrun(path='',code=None,options=None):
2426
""" Run a code checkers with given params.
2527
2628
:return errors: list of dictionaries with error's information
2729
2830
"""
2931
errors= []
30-
params=dict(ignore=options.ignore,select=options.select)
3132
fileconfig=dict()
32-
formaskinoptions.file_params:
33-
ifmask.match(path):
34-
fileconfig.update(options.file_params[mask])
33+
params=dict()
34+
linters=LINTERS
35+
linter_params=dict()
36+
37+
ifoptions:
38+
linters=options.linters
39+
linter_params=options.linter_params
40+
formaskinoptions.file_params:
41+
ifmask.match(path):
42+
fileconfig.update(options.file_params[mask])
3543

3644
try:
3745
withCodeContext(code,path)asctx:
@@ -41,51 +49,43 @@ def run(path, code=None, options=None):
4149
ifparams.get('skip'):
4250
returnerrors
4351

44-
foriteminoptions.linters:
52+
foriteminlinters:
4553

4654
ifnotisinstance(item,tuple):
4755
item= (item,LINTERS.get(item))
4856

49-
name,linter=item
57+
lname,linter=item
5058

51-
ifnotlinterornotlinter.allow(path):
59+
ifnotlinterorpathandnotlinter.allow(path):
5260
continue
5361

54-
LOGGER.info("Run %s",name)
55-
meta=options.linter_params.get(name,dict())
56-
result=linter.run(path,code=code,**meta)
57-
foreinresult:
58-
e['linter']=name
59-
e['col']=e.get('col')or0
60-
e['lnum']=e.get('lnum')or0
61-
e['type']=e.get('type')or'E'
62-
e['text']="%s [%s]"% (
63-
e.get('text','').strip().split('\n')[0],name)
64-
e['filename']=pathor''
65-
errors.append(e)
62+
LOGGER.info("Run %s",lname)
63+
meta=linter_params.get(lname,dict())
64+
errors+= [Error(filename=path,linter=lname,**e)
65+
foreinlinter.run(path,code=code,**meta)]
6666

6767
exceptIOErrorase:
6868
LOGGER.debug("IOError %s",e)
69-
errors.append(dict(
70-
lnum=0,type='E',col=0,text=str(e),filename=pathor''))
69+
errors.append(Error(text=str(e),filename=path,linter=lname))
7170

7271
exceptSyntaxErrorase:
7372
LOGGER.debug("SyntaxError %s",e)
74-
errors.append(dict(
75-
lnum=e.linenoor0,type='E',col=e.offsetor0,
76-
text=e.args[0]+' [%s]'%name,filename=pathor''
77-
))
73+
errors.append(
74+
Error(linter=lname,lnum=e.lineno,col=e.offset,text=e.args[0],
75+
filename=path))
7876

7977
exceptExceptionase:
8078
importtraceback
8179
LOGGER.info(traceback.format_exc())
8280

83-
errors= [erforerinerrorsiffilter_errors(er,**params)]
81+
errors=filter_errors(errors,**params)
82+
83+
errors=list(remove_duplicates(errors))
8484

8585
ifcodeanderrors:
8686
errors=filter_skiplines(code,errors)
8787

88-
returnsorted(errors,key=lambdax:x['lnum'])
88+
returnsorted(errors,key=lambdae:e.lnum)
8989

9090

9191
defparse_modeline(code):
@@ -107,7 +107,10 @@ def prepare_params(modeline, fileconfig, options):
107107
:return dict:
108108
109109
"""
110-
params=dict(ignore=options.ignore,select=options.select,skip=False)
110+
params=dict(skip=False,ignore=[],select=[])
111+
ifoptions:
112+
params['ignore']=options.ignore
113+
params['select']=options.select
111114

112115
forconfiginfilter(None, [modeline,fileconfig]):
113116
forkeyin ('ignore','select'):
@@ -120,23 +123,26 @@ def prepare_params(modeline, fileconfig, options):
120123
returnparams
121124

122125

123-
deffilter_errors(e,select=None,ignore=None,**params):
126+
deffilter_errors(errors,select=None,ignore=None,**params):
124127
""" Filter a erros by select and ignore options.
125128
126129
:return bool:
127130
128131
"""
129-
ifselect:
130-
forsinselect:
131-
ife['text'].startswith(s):
132-
returnTrue
133-
134-
ifignore:
135-
forsinignore:
136-
ife['text'].startswith(s):
137-
returnFalse
132+
select=selector []
133+
ignore=ignoreor []
138134

139-
returnTrue
135+
foreinerrors:
136+
forsinselect:
137+
ife.number.startswith(s):
138+
yielde
139+
break
140+
else:
141+
forsinignore:
142+
ife.number.startswith(s):
143+
break
144+
else:
145+
yielde
140146

141147

142148
deffilter_skiplines(code,errors):
@@ -148,18 +154,30 @@ def filter_skiplines(code, errors):
148154
ifnoterrors:
149155
returnerrors
150156

151-
enums=set(er['lnum']forerinerrors)
157+
enums=set(er.lnumforerinerrors)
152158
removed=set([
153159
numfornum,linenumerate(code.split('\n'),1)
154160
ifnuminenumsandSKIP_PATTERN(l)
155161
])
156162

157163
ifremoved:
158-
errors= [erforerinerrorsifnoter['lnum']inremoved]
164+
errors= [erforerinerrorsifer.lnumnotinremoved]
159165

160166
returnerrors
161167

162168

169+
defremove_duplicates(errors):
170+
""" Remove same errors from others linters. """
171+
passed=defaultdict(list)
172+
forerrorinerrors:
173+
key=error.linter,error.number
174+
ifkeyinDUPLICATES:
175+
ifkeyinpassed[error.lnum]:
176+
continue
177+
passed[error.lnum]=DUPLICATES[key]
178+
yielderror
179+
180+
163181
classCodeContext(object):
164182

165183
""" Read file if code is None. """

‎pymode/libs/pylama/errors.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
""" Dont duplicate errors same type. """
2+
3+
DUPLICATES= (
4+
5+
# multiple statements on one line
6+
[('pep8','E701'), ('pylint','C0321')],
7+
8+
# missing whitespace around operator
9+
[('pep8','E225'), ('pylint','C0326')],
10+
11+
# unused variable
12+
[('pylint','W0612'), ('pyflakes','W0612')],
13+
14+
# undefined variable
15+
[('pylint','E0602'), ('pyflakes','E0602')],
16+
17+
# unused import
18+
[('pylint','W0611'), ('pyflakes','W0611')],
19+
20+
# unexpected spaces
21+
[('pylint','C0326'), ('pep8','E251')],
22+
23+
# long lines
24+
[('pylint','C0301'), ('pep8','E501')],
25+
26+
# whitespace before '('
27+
[('pylint','C0326'), ('pep8','E211')],
28+
29+
# statement ends with a semicolon
30+
[('pylint','W0301'), ('pep8','E703')],
31+
32+
# multiple statements on one line
33+
[('pylint','C0321'), ('pep8','E702')],
34+
35+
)
36+
37+
DUPLICATES=dict((key,values)forvaluesinDUPLICATESforkeyinvalues)
38+
39+
40+
classError(object):
41+
42+
""" Store error information. """
43+
44+
def__init__(self,linter="",col=1,lnum=1,type="E",
45+
text="unknown error",filename="",**kwargs):
46+
""" Init error information with default values. """
47+
text=' '.join(str(text).strip().split('\n'))
48+
iflinter:
49+
text="%s [%s]"% (text,linter)
50+
number=text.split(' ',1)[0]
51+
self._info=dict(linter=linter,col=col,lnum=lnum,type=type,
52+
text=text,filename=filename,number=number)
53+
54+
def__getattr__(self,name):
55+
returnself._info[name]
56+
57+
def__getitem__(self,name):
58+
returnself._info[name]
59+
60+
def__repr__(self):
61+
return"<Error: %s %s>"% (self.number,self.linter)
62+
63+
# pylama:ignore=W0622,D

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp