Fix #680 - Use --shadow-file to check for problems with mypy while you type

This commit is contained in:
w0rp 2017-06-27 10:06:03 +01:00
parent 499bf63dc3
commit 16ba9bd680
7 changed files with 23 additions and 31 deletions

View File

@ -7,19 +7,7 @@ let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
let g:ale_python_mypy_use_global = get(g:, 'ale_python_mypy_use_global', 0) let g:ale_python_mypy_use_global = get(g:, 'ale_python_mypy_use_global', 0)
function! ale_linters#python#mypy#GetExecutable(buffer) abort function! ale_linters#python#mypy#GetExecutable(buffer) abort
if !ale#Var(a:buffer, 'python_mypy_use_global') return ale#python#FindExecutable(a:buffer, 'python_mypy', ['/bin/mypy'])
let l:virtualenv = ale#python#FindVirtualenv(a:buffer)
if !empty(l:virtualenv)
let l:ve_mypy = l:virtualenv . '/bin/mypy'
if executable(l:ve_mypy)
return l:ve_mypy
endif
endif
endif
return ale#Var(a:buffer, 'python_mypy_executable')
endfunction endfunction
function! ale_linters#python#mypy#GetCommand(buffer) abort function! ale_linters#python#mypy#GetCommand(buffer) abort
@ -33,7 +21,7 @@ function! ale_linters#python#mypy#GetCommand(buffer) abort
\ . ale#Escape(l:executable) \ . ale#Escape(l:executable)
\ . ' --show-column-numbers ' \ . ' --show-column-numbers '
\ . ale#Var(a:buffer, 'python_mypy_options') \ . ale#Var(a:buffer, 'python_mypy_options')
\ . ' %s' \ . ' --shadow-file %s %t %s'
endfunction endfunction
function! ale_linters#python#mypy#Handle(buffer, lines) abort function! ale_linters#python#mypy#Handle(buffer, lines) abort
@ -69,5 +57,4 @@ call ale#linter#Define('python', {
\ 'executable_callback': 'ale_linters#python#mypy#GetExecutable', \ 'executable_callback': 'ale_linters#python#mypy#GetExecutable',
\ 'command_callback': 'ale_linters#python#mypy#GetCommand', \ 'command_callback': 'ale_linters#python#mypy#GetCommand',
\ 'callback': 'ale_linters#python#mypy#Handle', \ 'callback': 'ale_linters#python#mypy#Handle',
\ 'lint_file': 1,
\}) \})

View File

@ -12,7 +12,7 @@ function! ale#fixers#autopep8#Fix(buffer) abort
\ ['/bin/autopep8'], \ ['/bin/autopep8'],
\) \)
if empty(l:executable) if !executable(l:executable)
return 0 return 0
endif endif

View File

@ -11,7 +11,7 @@ function! ale#fixers#isort#Fix(buffer) abort
\ ['/bin/isort'], \ ['/bin/isort'],
\) \)
if empty(l:executable) if !executable(l:executable)
return 0 return 0
endif endif

View File

@ -11,7 +11,7 @@ function! ale#fixers#yapf#Fix(buffer) abort
\ ['/bin/yapf'], \ ['/bin/yapf'],
\) \)
if empty(l:executable) if !executable(l:executable)
return 0 return 0
endif endif

View File

@ -58,11 +58,5 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
endfor endfor
endif endif
let l:global_executable = ale#Var(a:buffer, a:base_var_name . '_executable') return ale#Var(a:buffer, a:base_var_name . '_executable')
if executable(l:global_executable)
return l:global_executable
endif
return ''
endfunction endfunction

View File

@ -107,6 +107,11 @@ g:ale_python_isort_use_global *g:ale_python_isort_use_global*
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
mypy *ale-python-mypy* mypy *ale-python-mypy*
The minimum supported version of mypy that ALE supports is v0.4.4. This is
the first version containing the `--shadow-file` option ALE needs to be able
to check for errors while you type.
g:ale_python_mypy_executable *g:ale_python_mypy_executable* g:ale_python_mypy_executable *g:ale_python_mypy_executable*
*b:ale_python_mypy_executable* *b:ale_python_mypy_executable*
Type: |String| Type: |String|

View File

@ -20,7 +20,8 @@ Execute(The mypy callbacks should return the correct default values):
\ 'mypy', \ 'mypy',
\ ale_linters#python#mypy#GetExecutable(bufnr('')) \ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers %s', \ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr('')) \ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy executable should be configurable, and escaped properly): Execute(The mypy executable should be configurable, and escaped properly):
@ -30,14 +31,16 @@ Execute(The mypy executable should be configurable, and escaped properly):
\ 'executable with spaces', \ 'executable with spaces',
\ ale_linters#python#mypy#GetExecutable(bufnr('')) \ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ 'cd ''' . g:dir . ''' && ''executable with spaces'' --show-column-numbers %s', \ 'cd ''' . g:dir . ''' && ''executable with spaces'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr('')) \ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy command callback should let you set options): Execute(The mypy command callback should let you set options):
let g:ale_python_mypy_options = '--some-option' let g:ale_python_mypy_options = '--some-option'
AssertEqual AssertEqual
\ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers --some-option %s', \ 'cd ''' . g:dir . ''' && ''mypy'' --show-column-numbers --some-option '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr('')) \ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy command should switch directories to the detected project root): Execute(The mypy command should switch directories to the detected project root):
@ -47,7 +50,8 @@ Execute(The mypy command should switch directories to the detected project root)
\ 'mypy', \ 'mypy',
\ ale_linters#python#mypy#GetExecutable(bufnr('')) \ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ 'cd ''' . g:dir . '/python_paths/no_virtualenv/subdir'' && ''mypy'' --show-column-numbers %s', \ 'cd ''' . g:dir . '/python_paths/no_virtualenv/subdir'' && ''mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr('')) \ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(The mypy callbacks should detect virtualenv directories and switch to the project root): Execute(The mypy callbacks should detect virtualenv directories and switch to the project root):
@ -58,7 +62,8 @@ Execute(The mypy callbacks should detect virtualenv directories and switch to th
\ ale_linters#python#mypy#GetExecutable(bufnr('')) \ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && ''' \ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && '''
\ . g:dir . '/python_paths/with_virtualenv/env/bin/mypy'' --show-column-numbers %s', \ . g:dir . '/python_paths/with_virtualenv/env/bin/mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr('')) \ ale_linters#python#mypy#GetCommand(bufnr(''))
Execute(You should able able to use the global mypy instead): Execute(You should able able to use the global mypy instead):
@ -69,5 +74,6 @@ Execute(You should able able to use the global mypy instead):
\ 'mypy', \ 'mypy',
\ ale_linters#python#mypy#GetExecutable(bufnr('')) \ ale_linters#python#mypy#GetExecutable(bufnr(''))
AssertEqual AssertEqual
\ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && ''mypy'' --show-column-numbers %s', \ 'cd ''' . g:dir . '/python_paths/with_virtualenv/subdir'' && ''mypy'' --show-column-numbers '
\ . '--shadow-file %s %t %s',
\ ale_linters#python#mypy#GetCommand(bufnr('')) \ ale_linters#python#mypy#GetCommand(bufnr(''))