From ea6d720fecaf79b508535b9e82ecbb0eda0346b6 Mon Sep 17 00:00:00 2001 From: Derek P Sifford Date: Sun, 1 Jul 2018 14:59:49 -0400 Subject: [PATCH 1/4] add pyre lsp linter to python linters --- README.md | 2 +- ale_linters/python/pyre.vim | 29 +++++++++++++++++++++++++++++ doc/ale-python.txt | 24 ++++++++++++++++++++++++ doc/ale.txt | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ale_linters/python/pyre.vim diff --git a/README.md b/README.md index f0b40527..caddc590 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ formatting. | proto | [protoc-gen-lint](https://github.com/ckaznocha/protoc-gen-lint) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | -| Python | [autopep8](https://github.com/hhatto/autopep8), [black](https://github.com/ambv/black), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [prospector](http://github.com/landscapeio/prospector), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pyls](https://github.com/palantir/python-language-server), [pylint](https://www.pylint.org/) !!, [yapf](https://github.com/google/yapf) | +| Python | [autopep8](https://github.com/hhatto/autopep8), [black](https://github.com/ambv/black), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [prospector](http://github.com/landscapeio/prospector), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pyls](https://github.com/palantir/python-language-server), [pyre](https://github.com/facebook/pyre-check), [pylint](https://www.pylint.org/) !!, [yapf](https://github.com/google/yapf) | | QML | [qmlfmt](https://github.com/jesperhh/qmlfmt), [qmllint](https://github.com/qt/qtdeclarative/tree/5.11/tools/qmllint) | | R | [lintr](https://github.com/jimhester/lintr) | | ReasonML | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-reasonml-ols` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [refmt](https://github.com/reasonml/reason-cli) | diff --git a/ale_linters/python/pyre.vim b/ale_linters/python/pyre.vim new file mode 100644 index 00000000..13f77d68 --- /dev/null +++ b/ale_linters/python/pyre.vim @@ -0,0 +1,29 @@ +" Author: dsifford +" Description: A performant type-checker supporting LSP for Python 3 created by Facebook + +call ale#Set('python_pyre_executable', 'pyre') +call ale#Set('python_pyre_use_global', get(g:, 'ale_use_global_executables', 0)) + +function! ale_linters#python#pyre#GetExecutable(buffer) abort + return ale#python#FindExecutable(a:buffer, 'python_pyre', ['pyre']) +endfunction + +function! ale_linters#python#pyre#GetCommand(buffer) abort + let l:executable = ale_linters#python#pyre#GetExecutable(a:buffer) + + let l:exec_args = l:executable =~? 'pipenv$' + \ ? ' run pyre persistent' + \ : ' persistent' + + return ale#Escape(l:executable) . l:exec_args +endfunction + +call ale#linter#Define('python', { +\ 'name': 'pyre', +\ 'lsp': 'stdio', +\ 'executable_callback': 'ale_linters#python#pyre#GetExecutable', +\ 'command_callback': 'ale_linters#python#pyre#GetCommand', +\ 'language': 'python', +\ 'project_root_callback': 'ale#python#FindProjectRoot', +\ 'completion_filter': 'ale#completion#python#CompletionItemFilter', +\}) diff --git a/doc/ale-python.txt b/doc/ale-python.txt index b24b531d..de706896 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -363,6 +363,30 @@ g:ale_python_pyls_use_global *g:ale_python_pyls_use_global* See |ale-integrations-local-executables| +=============================================================================== +pyre *ale-python-pyre* + +`pyre` will be run from a detected project root, per |ale-python-root|. + + +g:ale_python_pyre_executable *g:ale_python_pyre_executable* + *b:ale_python_pyre_executable* + Type: |String| + Default: `'pyre'` + + See |ale-integrations-local-executables| + + Set this to `'pipenv'` to invoke `'pipenv` `run` `pyre'`. + + +g:ale_python_pyre_use_global *g:ale_python_pyre_use_global* + *b:ale_python_pyre_use_global* + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + =============================================================================== yapf *ale-python-yapf* diff --git a/doc/ale.txt b/doc/ale.txt index f8b3141c..1cc7a62e 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -199,6 +199,7 @@ CONTENTS *ale-contents* pyflakes............................|ale-python-pyflakes| pylint..............................|ale-python-pylint| pyls................................|ale-python-pyls| + pyre................................|ale-python-pyre| yapf................................|ale-python-yapf| qml...................................|ale-qml-options| qmlfmt..............................|ale-qml-qmlfmt| From 23394bf4a5c7f38687ddd5c9794538dd4e07717e Mon Sep 17 00:00:00 2001 From: Derek P Sifford Date: Sun, 1 Jul 2018 15:14:13 -0400 Subject: [PATCH 2/4] add pyre to table in doc/ale.txt --- doc/ale.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ale.txt b/doc/ale.txt index 1cc7a62e..d6b46ab0 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -391,7 +391,7 @@ Notes: * proto: `protoc-gen-lint` * Pug: `pug-lint` * Puppet: `puppet`, `puppet-lint` -* Python: `autopep8`, `black`, `flake8`, `isort`, `mypy`, `prospector`, `pycodestyle`, `pyls`, `pylint`!!, `yapf` +* Python: `autopep8`, `black`, `flake8`, `isort`, `mypy`, `prospector`, `pycodestyle`, `pyls`, `pyre`, `pylint`!!, `yapf` * QML: `qmlfmt`, `qmllint` * R: `lintr` * ReasonML: `merlin`, `ols`, `refmt` From 09a53fb363394a7d288fcf3a943fb635df8d3953 Mon Sep 17 00:00:00 2001 From: Derek P Sifford Date: Mon, 2 Jul 2018 18:23:42 -0400 Subject: [PATCH 3/4] add command_callback test --- .../test_pyre_command_callback.vader | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/command_callback/test_pyre_command_callback.vader diff --git a/test/command_callback/test_pyre_command_callback.vader b/test/command_callback/test_pyre_command_callback.vader new file mode 100644 index 00000000..395f951f --- /dev/null +++ b/test/command_callback/test_pyre_command_callback.vader @@ -0,0 +1,56 @@ +Before: + Save g:ale_python_pyre_executable + Save g:ale_python_pyre_use_global + + unlet! g:ale_python_pyre_executable + unlet! g:ale_python_pyre_use_global + + let b:bin_dir = has('win32') ? 'Scripts' : 'bin' + + call ale#test#SetDirectory('/testplugin/test/command_callback') + + runtime ale_linters/python/pyre.vim + +After: + Restore + + unlet! b:bin_dir + unlet! b:executable + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(The pyre command callback should return default string): + AssertEqual ale#Escape('pyre') . ' persistent', + \ ale_linters#python#pyre#GetCommand(bufnr('')) + +Execute(The pyre executable should be configurable): + let g:ale_python_pyre_executable = '~/.local/bin/pyre' + + AssertEqual ale#Escape('~/.local/bin/pyre') . ' persistent', + \ ale_linters#python#pyre#GetCommand(bufnr('')) + +Execute(The pyre executable should be run from the virtualenv path): + call ale#test#SetFilename('python_paths/with_virtualenv/subdir/foo/bar.py') + + let b:executable = ale#path#Simplify( + \ g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/pyre' + \) + + AssertEqual ale#Escape(b:executable) . ' persistent', + \ ale_linters#python#pyre#GetCommand(bufnr('')) + +Execute(You should be able to override the pyre virtualenv lookup): + call ale#test#SetFilename('python_paths/with_virtualenv/subdir/foo/bar.py') + + let g:ale_python_pyre_use_global = 1 + + AssertEqual ale#Escape('pyre') . ' persistent', + \ ale_linters#python#pyre#GetCommand(bufnr('')) + +Execute(Setting executable to 'pipenv' appends 'run pyre'): + let g:ale_python_pyre_executable = 'path/to/pipenv' + + AssertEqual + \ ale#Escape('path/to/pipenv') . ' run pyre persistent', + \ ale_linters#python#pyre#GetCommand(bufnr('')) From 20ed48352fd153669dc6c3d17da9c3e5f8773299 Mon Sep 17 00:00:00 2001 From: Derek P Sifford Date: Mon, 2 Jul 2018 18:49:12 -0400 Subject: [PATCH 4/4] add dummy pyre binary and executable --- .../python_paths/with_virtualenv/env/Scripts/pyre.exe | 0 test/command_callback/python_paths/with_virtualenv/env/bin/pyre | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100755 test/command_callback/python_paths/with_virtualenv/env/Scripts/pyre.exe create mode 100755 test/command_callback/python_paths/with_virtualenv/env/bin/pyre diff --git a/test/command_callback/python_paths/with_virtualenv/env/Scripts/pyre.exe b/test/command_callback/python_paths/with_virtualenv/env/Scripts/pyre.exe new file mode 100755 index 00000000..e69de29b diff --git a/test/command_callback/python_paths/with_virtualenv/env/bin/pyre b/test/command_callback/python_paths/with_virtualenv/env/bin/pyre new file mode 100755 index 00000000..e69de29b