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

Commit35d5349

Browse files
committed
Update pylama
1 parentf756847 commit35d5349

File tree

84 files changed

+307
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+307
-29
lines changed

‎pylibs/autopep8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
importdifflib
5555
importtempfile
5656

57-
frompylama.checkersimportpep8
57+
frompylama.lint.pylama_pep8importpep8
5858

5959

6060
try:

‎pylibs/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_info=1,5,3
8+
version_info=2,0,1
99

1010
__version__=version='.'.join(map(str,version_info))
1111
__project__=__name__

‎pylibs/pylama/checkers/pylint/logilab/__init__.py

Whitespace-only changes.

‎pylibs/pylama/config.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
""" Parse arguments from command line and configuration files. """
22
importfnmatch
3-
importlogging
4-
fromargparseimportArgumentParser,NamespaceasOptions
53
fromosimportgetcwd,path
64
fromreimportcompileasre
75

8-
from .importversion,utils
9-
from .coreimportDEFAULT_LINTERS,LOGGER,STREAM
6+
importlogging
7+
fromargparseimportArgumentParser,NamespaceasOptions
8+
9+
from .importversion
10+
from .coreimportLOGGER,STREAM
1011
from .iniramaimportNamespace
12+
from .lintimportLINTERS
13+
1114

15+
#: A default checkers
16+
DEFAULT_LINTERS='pep8','pyflakes','mccabe'
1217

18+
#: A default complexity for mccabe checker
1319
DEFAULT_COMPLEXITY=10
20+
1421
CURDIR=getcwd()
1522
DEFAULT_INI_PATH=path.join(CURDIR,'pylama.ini')
1623

@@ -30,7 +37,7 @@ def parse_options(
3037
async=_Default(async),format=_Default('pep8'),
3138
select=_Default(select),ignore=_Default(ignore),
3239
report=_Default(None),verbose=_Default(False),
33-
linters=_Default(linters),complexity=_Default(complexity),
40+
linters=_Default(','.join(linters)),complexity=_Default(complexity),
3441
options=_Default(options))
3542

3643
ifnot (argsisNone):
@@ -114,12 +121,19 @@ def get_parser():
114121
"--select","-s",default=_Default(''),type=split_csp_str,
115122
help="Select errors and warnings. (comma-separated)")
116123

124+
defparse_linters(csp_str):
125+
result=list()
126+
fornameinsplit_csp_str(csp_str):
127+
linter=LINTERS.get(name)
128+
iflinter:
129+
result.append((name,linter))
130+
returnresult
131+
117132
parser.add_argument(
118133
"--linters","-l",default=_Default(','.join(DEFAULT_LINTERS)),
119-
type=split_csp_str,
120-
help=(
134+
type=parse_linters,help=(
121135
"Select linters. (comma-separated). Choices are %s."
122-
%','.join(sforsinutils.__all__)
136+
%','.join(sforsinLINTERS.keys())
123137
))
124138

125139
parser.add_argument(

‎pylibs/pylama/core.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
"""
66
importlogging
77
importre
8-
9-
from .importutils
10-
11-
12-
#: A default checkers
13-
DEFAULT_LINTERS='pep8','pyflakes','mccabe'
8+
from .lintimportLINTERS
149

1510
#: The skip pattern
1611
SKIP_PATTERN=re.compile(r'# *noqa\b',re.I).search
@@ -25,14 +20,14 @@
2520
LOGGER.addHandler(STREAM)
2621

2722

28-
defrun(path,ignore=None,select=None,linters=DEFAULT_LINTERS,config=None,
29-
**meta):
23+
defrun(path,ignore=None,select=None,linters=None,config=None,**meta):
3024
""" Run a code checkers with given params.
3125
3226
:return errors: list of dictionaries with error's information
3327
3428
"""
3529
errors= []
30+
linters=lintersorLINTERS.items()
3631
params=dict(ignore=ignore,select=select)
3732
code=None
3833
try:
@@ -46,21 +41,24 @@ def run(path, ignore=None, select=None, linters=DEFAULT_LINTERS, config=None,
4641
ifnotparams['lint']:
4742
returnerrors
4843

49-
forlintinlinters:
50-
try:
51-
linter=getattr(utils,lint)
52-
exceptAttributeError:
53-
LOGGER.warning("Linter `%s` not found.",lint)
44+
foriteminlinters:
45+
46+
ifnotisinstance(item,tuple):
47+
item= (item,LINTERS.get(item))
48+
49+
name,linter=item
50+
51+
ifnotlinterornotlinter.allow(path):
5452
continue
5553

56-
result=linter(path,code=code,**meta)
54+
result=linter.run(path,code=code,**meta)
5755
foreinresult:
5856
e['col']=e.get('col')or0
5957
e['lnum']=e.get('lnum')or0
6058
e['type']=e.get('type')or'E'
6159
e['text']="{0} [{1}]".format((e.get(
6260
'text')or'').strip()
63-
.replace("'","\"").split('\n')[0],lint)
61+
.replace("'","\"").split('\n')[0],name)
6462
e['filename']=pathor''
6563
errors.append(e)
6664

@@ -71,7 +69,7 @@ def run(path, ignore=None, select=None, linters=DEFAULT_LINTERS, config=None,
7169
exceptSyntaxErrorase:
7270
errors.append(dict(
7371
lnum=e.linenoor0,type='E',col=e.offsetor0,
74-
text=e.args[0]+' [%s]'%lint,filename=pathor''
72+
text=e.args[0]+' [%s]'%name,filename=pathor''
7573
))
7674

7775
exceptException:
@@ -128,7 +126,6 @@ def filter_errors(e, select=None, ignore=None, **params):
128126
:return bool:
129127
130128
"""
131-
132129
ifselect:
133130
forsinselect:
134131
ife['text'].startswith(s):

‎pylibs/pylama/lint/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
""" Custom module loader. """
2+
3+
4+
classLinter(object):# noqa
5+
6+
""" Abstract class for linter plugin. """
7+
8+
@staticmethod
9+
defallow(path):
10+
""" Check path is relevant for linter.
11+
12+
:return bool:
13+
14+
"""
15+
16+
returnpath.endswith('.py')
17+
18+
@staticmethod
19+
defrun(path,**meta):
20+
""" Method 'run' should be defined. """
21+
22+
raiseNotImplementedError(__doc__)
23+
24+
25+
LINTERS=dict()
26+
27+
28+
fromosimportlistdir,pathasop
29+
30+
curdir=op.dirname(__file__)
31+
forpinlistdir(curdir):
32+
ifp.startswith('pylama')andop.isdir(op.join(curdir,p)):
33+
name=p[len('pylama_'):]
34+
module=__import__(
35+
'pylama.lint.pylama_%s'%name,globals(),locals(), ['Linter'])
36+
LINTERS[name]=getattr(module,'Linter')()
37+
38+
# try:
39+
# from pkg_resources import iter_entry_points
40+
41+
# for entry in iter_entry_points('pylama.linter'):
42+
# LINTERS[entry.name] = entry.load()()
43+
# except ImportError:
44+
# pass
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
""" Check complexity. """
2+
3+
from ..importLinterasBaseLinter
4+
5+
6+
classLinter(BaseLinter):
7+
8+
""" Mccabe code complexity. """
9+
10+
@staticmethod
11+
defrun(path,code=None,complexity=8,**meta):
12+
""" MCCabe code checking.
13+
14+
:return list: List of errors.
15+
16+
"""
17+
from .mccabeimportget_code_complexity
18+
19+
returnget_code_complexity(code,complexity,filename=path)or []
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
""" Check PEP257. """
2+
3+
from ..importLinterasBaseLinter
4+
5+
6+
classLinter(BaseLinter):
7+
8+
""" Mccabe code complexity. """
9+
10+
@staticmethod
11+
defrun(path,**meta):
12+
""" PEP257 code checking.
13+
14+
:return list: List of errors.
15+
16+
"""
17+
f=open(path)
18+
from .pep257importcheck_source
19+
20+
errors= []
21+
forerincheck_source(f.read(),path):
22+
errors.append(dict(
23+
lnum=er.line,
24+
col=er.char,
25+
text='C0110 %s'%er.explanation.split('\n')[0].strip(),
26+
type='W',
27+
))
28+
returnerrors
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
""" Check PEP8. """
2+
from ..importLinterasBaseLinter
3+
from .pep8importBaseReport,StyleGuide
4+
5+
6+
classLinter(BaseLinter):
7+
8+
""" PEP8 code check. """
9+
10+
@staticmethod
11+
defrun(path,**meta):
12+
""" PEP8 code checking.
13+
14+
:return list: List of errors.
15+
16+
"""
17+
P8Style=StyleGuide(reporter=_PEP8Report)
18+
returnP8Style.input_file(path)
19+
20+
21+
class_PEP8Report(BaseReport):
22+
23+
def__init__(self,*args,**kwargs):
24+
super(_PEP8Report,self).__init__(*args,**kwargs)
25+
self.errors= []
26+
27+
definit_file(self,filename,lines,expected,line_offset):
28+
""" Prepare storage for errors. """
29+
super(_PEP8Report,self).init_file(
30+
filename,lines,expected,line_offset)
31+
self.errors= []
32+
33+
deferror(self,line_number,offset,text,check):
34+
""" Save errors. """
35+
code=super(_PEP8Report,self).error(
36+
line_number,offset,text,check)
37+
38+
self.errors.append(dict(
39+
text=text,
40+
type=code,
41+
col=offset+1,
42+
lnum=line_number,
43+
))
44+
45+
defget_file_results(self):
46+
""" Get errors.
47+
48+
:return list: List of errors.
49+
50+
"""
51+
returnself.errors
File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
""" Check Pyflakes. """
2+
3+
from ..importLinterasBaseLinter
4+
5+
6+
classLinter(BaseLinter):
7+
8+
""" Pyflakes code check. """
9+
10+
@staticmethod
11+
defrun(path,code=None,**meta):
12+
""" Pyflake code checking.
13+
14+
:return list: List of errors.
15+
16+
"""
17+
import_ast
18+
from .pyflakesimportchecker
19+
20+
errors= []
21+
tree=compile(code,path,"exec",_ast.PyCF_ONLY_AST)
22+
w=checker.Checker(tree,path)
23+
w.messages=sorted(w.messages,key=lambdam:m.lineno)
24+
forwinw.messages:
25+
errors.append(dict(
26+
lnum=w.lineno,
27+
text=w.message%w.message_args,
28+
))
29+
returnerrors
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
""" Description. """
2+
3+
# Module information
4+
# ==================
5+
6+
7+
__version__='0.1.0'
8+
__project__='pylama_pylint'
9+
__author__="horneds <horneds@gmail.com>"
10+
__license__="BSD"
11+
12+
from .mainimportLinter

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp