|
3 | 3 | import locale |
4 | 4 | import json |
5 | 5 |
|
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 |
7 | 9 |
|
8 | | -from .interface import get_option, get_var, get_current_buffer, command |
| 10 | +from . import interface |
9 | 11 | from .queue import add_task |
10 | 12 |
|
11 | 13 |
|
|
16 | 18 |
|
17 | 19 |
|
18 | 20 | 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')) |
20 | 29 |
|
21 | 30 | ignore = set([ |
22 | 31 | 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 |
26 | 36 | ]) |
| 37 | + |
27 | 38 | select = set([ |
28 | 39 | 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 |
32 | 44 | ]) |
33 | 45 |
|
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]) |
36 | 52 |
|
37 | 53 | add_task( |
38 | 54 | run_checkers, |
39 | 55 | callback=parse_result, |
40 | 56 | title='Code checking', |
41 | 57 |
|
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 | + ) |
47 | 62 |
|
48 | 63 |
|
49 | 64 | def run_checkers(checkers=None, ignore=None, buf=None, select=None, |
50 | | - complexity=None, callback=None): |
| 65 | + complexity=None, callback=None, config=None): |
51 | 66 |
|
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() |
54 | 69 |
|
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) |
57 | 73 |
|
58 | 74 |
|
59 | 75 | 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)) |
62 | 78 |
|
63 | 79 | # pymode:lint_ignore=W0622 |
0 commit comments