Skip to content

Commit 77d60d5

Browse files
committed
Lint respects pylama.ini and pymode.ini files.
1 parent 4648395 commit 77d60d5

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

pylibs/pylama/inirama.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ def __getitem__(self, name):
258258
self.sections[name] = self.section_type(self)
259259
return self.sections[name]
260260

261+
def __contains__(self, name):
262+
return name in self.sections
263+
261264
def __repr__(self):
262265
return "<Namespace: {0}>".format(self.sections)
263266

pylibs/pymode/interface.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def get_var(name):
1212

1313

1414
def get_bvar(name):
15-
return (int(vim.eval("exists('b:pymode_%s')" % name)) and vim.eval("b:pymode_%s" % name)) or None
15+
return (int(vim.eval("exists('b:pymode_%s')" % name))
16+
and vim.eval("b:pymode_%s" % name)) or None
1617

1718

1819
def get_current_buffer():
@@ -24,4 +25,10 @@ def show_message(message):
2425

2526

2627
def command(cmd):
27-
vim.command(cmd)
28+
return vim.command(cmd)
29+
30+
31+
def eval_code(code):
32+
return vim.eval(code)
33+
34+
# lint_ignore=F0401

pylibs/pymode/lint.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import locale
44
import json
55

6-
from pylama.main import run
6+
from pylama.main import run, prepare_params
7+
from pylama.inirama import Namespace
8+
from os import path as op
79

8-
from .interface import get_option, get_var, get_current_buffer, command
10+
from . import interface
911
from .queue import add_task
1012

1113

@@ -16,48 +18,62 @@
1618

1719

1820
def check_file():
19-
checkers = get_option('lint_checker').split(',')
21+
checkers = interface.get_option('lint_checker').split(',')
22+
buf = interface.get_current_buffer()
23+
24+
# Check configuration from `pymode.ini`
25+
curdir = interface.eval_code('getcwd()')
26+
config = Namespace()
27+
config.default_section = 'main'
28+
config.read(op.join(curdir, 'pylama.ini'), op.join(curdir, 'pymode.ini'))
2029

2130
ignore = set([
2231
i for i in (
23-
get_option('lint_ignore').split(',') +
24-
get_var('lint_ignore').split(','))
25-
if i
32+
interface.get_option('lint_ignore').split(',') +
33+
interface.get_var('lint_ignore').split(',') +
34+
config.default.get('ignore', '').split(',')
35+
) if i
2636
])
37+
2738
select = set([
2839
s for s in (
29-
get_option('lint_select').split(',') +
30-
get_var('lint_select').split(','))
31-
if s
40+
interface.get_option('lint_select').split(',') +
41+
interface.get_var('lint_select').split(',') +
42+
config.default.get('select', '').split(',')
43+
) if s
3244
])
3345

34-
buf = get_current_buffer()
35-
complexity = int(get_option('lint_mccabe_complexity') or 0)
46+
complexity = int(interface.get_option('lint_mccabe_complexity') or 0)
47+
48+
params = None
49+
relpath = op.relpath(buf.name, curdir)
50+
if relpath in config:
51+
params = prepare_params(config[relpath])
3652

3753
add_task(
3854
run_checkers,
3955
callback=parse_result,
4056
title='Code checking',
4157

42-
checkers=checkers,
43-
ignore=ignore,
44-
buf=buf,
45-
select=select,
46-
complexity=complexity)
58+
# params
59+
checkers=checkers, ignore=ignore, buf=buf, select=select,
60+
complexity=complexity, config=params,
61+
)
4762

4863

4964
def run_checkers(checkers=None, ignore=None, buf=None, select=None,
50-
complexity=None, callback=None):
65+
complexity=None, callback=None, config=None):
5166

52-
filename = buf.name
53-
pylint_options = '--rcfile={0} -r n'.format(get_var('lint_config')).split()
67+
pylint_options = '--rcfile={0} -r n'.format(
68+
interface.get_var('lint_config')).split()
5469

55-
return run(filename, ignore=ignore, select=select, linters=checkers,
56-
pylint=pylint_options, complexity=complexity)
70+
return run(
71+
buf.name, ignore=ignore, select=select, linters=checkers,
72+
pylint=pylint_options, complexity=complexity, config=config)
5773

5874

5975
def parse_result(result, buf=None, **kwargs):
60-
command('let g:qf_list = ' + json.dumps(result))
61-
command('call pymode#lint#Parse({0})'.format(buf.number))
76+
interface.command('let g:qf_list = ' + json.dumps(result))
77+
interface.command('call pymode#lint#Parse({0})'.format(buf.number))
6278

6379
# pymode:lint_ignore=W0622

0 commit comments

Comments
 (0)