Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Install into the same virtualenv as pyls itself.

Configuration
-------------
``prepend`` (default is ``[]``) list of additional command-line options to prepend

``live_mode`` (default is True) provides type checking as you type.

Expand All @@ -41,7 +42,8 @@ Depending on your editor, the configuration should be roughly like this:
"pyls_mypy":
{
"enabled": true,
"live_mode": false
"live_mode": false,
"prepend": ["--python-executable", "/tmp/foo/bin/python"]
}
}
}
4 changes: 4 additions & 0 deletions pyls_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def pyls_lint(config, workspace, document, is_saved):
if settings.get('strict', False):
args.append('--strict')

prepend = settings.get('prepend')
if prepend:
args = prepend + args

report, errors, _ = mypy_api.run(args)

diagnostics = []
Expand Down
35 changes: 35 additions & 0 deletions test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,38 @@ def test_parse_line_with_context(monkeypatch, word, bounds):
assert diag['message'] == '"Request" has no attribute "id"'
assert diag['range']['start'] == {'line': 278, 'character': bounds[0]}
assert diag['range']['end'] == {'line': 278, 'character': bounds[1]}


def test_option_prepend(tmpdir, monkeypatch):
import sys
from textwrap import dedent

sentinel = tmpdir / 'ran'

source = dedent(
"""\
#!/bin/sh
touch {}
exec {} "$@"
"""
).format(sentinel, sys.executable)

wrapper = tmpdir / 'bin/wrapper'
wrapper.write(source, ensure=True)
wrapper.chmod(0o700)

monkeypatch.setattr(
FakeConfig,
'plugin_settings',
lambda *_: {'prepend': ['--python-executable', wrapper.strpath]}
)

assert not sentinel.exists()
diags = plugin.pyls_lint(
config=FakeConfig(),
workspace=None,
document=Document(DOC_URI, DOC_TYPE_ERR),
is_saved=False,
)
assert len(diags) == 1
assert sentinel.exists()