Skip to content

Commit 30a995a

Browse files
mpanarinccordoba12
authored andcommitted
[add] --config param for flake8 (#700)
1 parent 143d993 commit 30a995a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pyls/plugins/flake8_lint.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2019 Palantir Technologies, Inc.
22
"""Linter pluging for flake8"""
33
import logging
4+
from os import path
45
import re
56
from subprocess import Popen, PIPE
67
from pyls import hookimpl, lsp
@@ -20,6 +21,7 @@ def pyls_lint(config, document):
2021
log.debug("Got flake8 settings: %s", settings)
2122

2223
opts = {
24+
'config': settings.get('config'),
2325
'exclude': settings.get('exclude'),
2426
'filename': settings.get('filename'),
2527
'hang-closing': settings.get('hangClosing'),
@@ -28,6 +30,14 @@ def pyls_lint(config, document):
2830
'select': settings.get('select'),
2931
}
3032

33+
# flake takes only absolute path to the config. So we should check and
34+
# convert if necessary
35+
if opts.get('config') and not path.isabs(opts.get('config')):
36+
opts['config'] = path.abspath(path.expanduser(path.expandvars(
37+
opts.get('config')
38+
)))
39+
log.debug("using flake8 with config: %s", opts['config'])
40+
3141
# Call the flake8 utility then parse diagnostics from stdout
3242
args = build_args(opts, document.path)
3343
output = run_flake8(args)
@@ -64,16 +74,17 @@ def build_args(options, doc_path):
6474
"""
6575
args = [doc_path]
6676
for arg_name, arg_val in options.items():
77+
if arg_val is None:
78+
continue
6779
arg = None
6880
if isinstance(arg_val, list):
6981
arg = '--{}={}'.format(arg_name, ','.join(arg_val))
7082
elif isinstance(arg_val, bool):
7183
if arg_val:
7284
arg = '--{}'.format(arg_name)
73-
elif isinstance(arg_val, int):
85+
else:
7486
arg = '--{}={}'.format(arg_name, arg_val)
75-
if arg:
76-
args.append(arg)
87+
args.append(arg)
7788
return args
7889

7990

test/plugins/test_flake8_lint.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright 2019 Palantir Technologies, Inc.
22
import tempfile
33
import os
4+
from mock import patch
5+
46
from pyls import lsp, uris
57
from pyls.plugins import flake8_lint
68
from pyls.workspace import Document
@@ -50,3 +52,14 @@ def test_flake8_lint(config):
5052

5153
finally:
5254
os.remove(name)
55+
56+
57+
def test_flake8_config_param(config):
58+
with patch('pyls.plugins.flake8_lint.Popen') as popen_mock:
59+
flake8_conf = '/tmp/some.cfg'
60+
config.update({'plugins': {'flake8': {'config': flake8_conf}}})
61+
_name, doc = temp_document(DOC)
62+
flake8_lint.pyls_lint(config, doc)
63+
call_args = popen_mock.call_args.args[0]
64+
assert 'flake8' in call_args
65+
assert '--config={}'.format(flake8_conf) in call_args

0 commit comments

Comments
 (0)