X Tutup
Skip to content

Commit e63911f

Browse files
committed
Update pylama
1 parent c3ef2c4 commit e63911f

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

ftplugin/python/pymode.vim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ if pymode#Option('lint')
7474
endif
7575

7676
" DESC: Run queue
77-
let &l:updatetime = g:pymode_updatetime
78-
au CursorHold <buffer> call pymode#queue#Poll()
79-
au BufLeave <buffer> Python queue.stop_queue()
77+
if pymode#Option('lint_async')
78+
let &l:updatetime = g:pymode_updatetime
79+
au CursorHold <buffer> call pymode#queue#Poll()
80+
au BufLeave <buffer> Python queue.stop_queue()
81+
endif
8082

8183
endif
8284

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, 0
8+
version_info = 1, 5, 2
99

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

pylibs/pylama/checkers/mccabe.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,13 @@ def get_code_complexity(code, threshold=7, filename='stdin'):
265265
complx = []
266266
McCabeChecker.max_complexity = threshold
267267
for lineno, offset, text, check in McCabeChecker(tree, filename).run():
268-
complx.append('%s:%d:1: %s' % (filename, lineno, text))
268+
complx.append(dict(
269+
type=McCabeChecker._code,
270+
lnum=lineno,
271+
text=text,
272+
))
269273

270-
if len(complx) == 0:
271-
return 0
272-
print('\n'.join(complx))
273-
return len(complx)
274+
return complx
274275

275276

276277
def get_module_complexity(module_path, threshold=7):

pylibs/pylama/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def parse_options(
2323
:return argparse.Namespace:
2424
2525
"""
26+
# Parse args from command string
2627
parser = get_parser()
2728
actions = dict((a.dest, a) for a in parser._actions)
2829
options = Options(
@@ -35,8 +36,10 @@ def parse_options(
3536
if not (args is None):
3637
options = parser.parse_args(args)
3738

39+
# Parse options from ini file
3840
config = get_config(str(options.options))
3941

42+
# Compile options from ini
4043
for k, v in config.default.items():
4144
value = getattr(options, k, _Default(None))
4245
if not isinstance(value, _Default):
@@ -50,6 +53,7 @@ def parse_options(
5053
value = bool(int(value))
5154
setattr(options, name, value)
5255

56+
# Postprocess options
5357
opts = dict(options.__dict__.items())
5458
for name, value in opts.items():
5559
if isinstance(value, _Default):
@@ -59,6 +63,7 @@ def parse_options(
5963

6064
setattr(options, name, value.value)
6165

66+
# Parse file related options
6267
options.file_params = dict()
6368
for k, s in config.sections.items():
6469
if k != config.default_section:

pylibs/pylama/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def shell(args=None, error=True):
2525

2626
options = parse_options(args)
2727
setup_logger(options)
28+
LOGGER.info(options)
2829

2930
# Install VSC hook
3031
if options.hook:

pylibs/pymode/lint.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import locale
66

7+
from os import path as op
78
from pylama.main import parse_options
89
from pylama.tasks import check_path
910

@@ -20,6 +21,7 @@
2021
def check_file():
2122
""" Check current buffer. """
2223
buf = interface.get_current_buffer()
24+
rootpath = interface.eval_code('getcwd()')
2325

2426
async = int(interface.get_option('lint_async'))
2527
linters = interface.get_option('lint_checker')
@@ -33,15 +35,15 @@ def check_file():
3335
if async:
3436
add_task(
3537
run_checkers, callback=parse_result, title='Code checking',
36-
buf=buf, options=options,
38+
buf=buf, options=options, rootpath=rootpath,
3739
)
3840

3941
else:
40-
result = run_checkers(buf=buf, options=options)
42+
result = run_checkers(buf=buf, options=options, rootpath=rootpath)
4143
parse_result(result, buf=buf)
4244

4345

44-
def run_checkers(callback=None, buf=None, options=None):
46+
def run_checkers(callback=None, buf=None, options=None, rootpath=None):
4547
""" Run pylama code.
4648
4749
:return list: errors
@@ -50,7 +52,10 @@ def run_checkers(callback=None, buf=None, options=None):
5052
pylint_options = '--rcfile={0} -r n'.format(
5153
interface.get_var('lint_config')).split()
5254

53-
return check_path(buf.name, options=options, pylint=pylint_options)
55+
path = buf.name
56+
if rootpath:
57+
path = op.relpath(path, rootpath)
58+
return check_path(path, options=options, pylint=pylint_options)
5459

5560

5661
def parse_result(result, buf=None, **kwargs):

0 commit comments

Comments
 (0)
X Tutup