Skip to content

Commit 159a7b8

Browse files
committed
fixup! Allow usage of pylint via stdin
1 parent de687cf commit 159a7b8

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

pyls/plugins/pylint_lint.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def pyls_lint(config, document, is_saved):
169169
"""Run pylint linter."""
170170
settings = config.plugin_settings('pylint')
171171
log.debug("Got pylint settings: %s", settings)
172-
if settings.get('executable'):
172+
# pylint >= 2.5.0 is required for working through stdin and only
173+
# available with python3
174+
if settings.get('executable') and sys.version_info[0] >= 3:
173175
flags = build_args_stdio(settings)
174176
pylint_executable = settings.get('executable', 'pylint')
175177
return pylint_lint_stdin(pylint_executable, document, flags)

setup.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import sys
23
from setuptools import find_packages, setup
34
import versioneer
45

@@ -53,7 +54,9 @@
5354
'pycodestyle>=2.6.0,<2.7.0',
5455
'pydocstyle>=2.0.0',
5556
'pyflakes>=2.2.0,<2.3.0',
56-
'pylint>=2.5.0',
57+
# pylint >= 2.5.0 is required for working through stdin and only
58+
# available with python3
59+
'pylint>=2.5.0' if sys.version_info.major >= 3 else 'pylint',
5760
'rope>=0.10.5',
5861
'yapf',
5962
],
@@ -63,12 +66,14 @@
6366
'pycodestyle': ['pycodestyle>=2.6.0,<2.7.0'],
6467
'pydocstyle': ['pydocstyle>=2.0.0'],
6568
'pyflakes': ['pyflakes>=2.2.0,<2.3.0'],
66-
'pylint': ['pylint>=2.5.0'],
69+
'pylint': [
70+
'pylint>=2.5.0' if sys.version_info.major >= 3 else 'pylint'],
6771
'rope': ['rope>0.10.5'],
6872
'yapf': ['yapf'],
69-
'test': ['versioneer', 'pylint>=2.5.0', 'pytest', 'mock', 'pytest-cov',
70-
'coverage', 'numpy', 'pandas', 'matplotlib',
71-
'pyqt5;python_version>="3"'],
73+
'test': ['versioneer',
74+
'pylint>=2.5.0' if sys.version_info.major >= 3 else 'pylint',
75+
'pytest', 'mock', 'pytest-cov', 'coverage', 'numpy', 'pandas',
76+
'matplotlib', 'pyqt5;python_version>="3"'],
7277
},
7378

7479
# To provide executable scripts, use entry points in preference to the

test/plugins/test_pylint_lint.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import tempfile
55

6-
from test import py2_only, py3_only
6+
from test import py2_only, py3_only, IS_PY3
77
from pyls import lsp, uris
88
from pyls.workspace import Document
99
from pyls.plugins import pylint_lint
@@ -49,15 +49,19 @@ def test_pylint(config, workspace):
4949
assert unused_import['range']['start'] == {'line': 0, 'character': 0}
5050
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
5151

52-
# test running pylint in stdin
53-
config.plugin_settings('pylint')['executable'] = 'pylint'
54-
diags = pylint_lint.pyls_lint(config, doc, True)
52+
if IS_PY3:
53+
# test running pylint in stdin
54+
config.plugin_settings('pylint')['executable'] = 'pylint'
55+
diags = pylint_lint.pyls_lint(config, doc, True)
5556

56-
msg = 'Unused import sys (unused-import)'
57-
unused_import = [d for d in diags if d['message'] == msg][0]
57+
msg = 'Unused import sys (unused-import)'
58+
unused_import = [d for d in diags if d['message'] == msg][0]
5859

59-
assert unused_import['range']['start'] == {'line': 0, 'character': 0}
60-
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
60+
assert unused_import['range']['start'] == {
61+
'line': 0,
62+
'character': 0,
63+
}
64+
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
6165

6266

6367
@py3_only
@@ -90,14 +94,6 @@ def test_syntax_error_pylint_py2(config, workspace):
9094
assert diag['range']['start'] == {'line': 0, 'character': 0}
9195
assert diag['severity'] == lsp.DiagnosticSeverity.Error
9296

93-
# test running pylint in stdin
94-
config.plugin_settings('pylint')['executable'] = 'pylint'
95-
96-
assert diag['message'].startswith('invalid syntax')
97-
# Pylint doesn't give column numbers for invalid syntax.
98-
assert diag['range']['start'] == {'line': 0, 'character': 0}
99-
assert diag['severity'] == lsp.DiagnosticSeverity.Error
100-
10197

10298
def test_lint_free_pylint(config, workspace):
10399
# Can't use temp_document because it might give us a file that doesn't

vscode-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
"pyls.plugins.pylint.executable": {
263263
"type": "string",
264264
"default": null,
265-
"description": "Executable to run pylint with. Enabling this will run pylint on unsaved files via stdin. Can slow down workflow."
265+
"description": "Executable to run pylint with. Enabling this will run pylint on unsaved files via stdin. Can slow down workflow. Only works with python3."
266266
},
267267
"pyls.plugins.rope_completion.enabled": {
268268
"type": "boolean",

0 commit comments

Comments
 (0)