2017-01-20 12:30:23 -05:00
|
|
|
" Author: Keith Smiley <k@keith.so>, w0rp <devw0rp@gmail.com>
|
2016-12-30 19:06:49 -05:00
|
|
|
" Description: mypy support for optional python typechecking
|
|
|
|
|
2017-05-06 18:19:54 -04:00
|
|
|
let g:ale_python_mypy_executable =
|
|
|
|
\ get(g:, 'ale_python_mypy_executable', 'mypy')
|
2017-01-18 05:31:36 -05:00
|
|
|
let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
|
2017-05-06 18:19:54 -04:00
|
|
|
let g:ale_python_mypy_use_global = get(g:, 'ale_python_mypy_use_global', 0)
|
|
|
|
|
|
|
|
" (cd /home/w0rp/git/wazoku/wazoku-spotlight && /home/w0rp/git/wazoku/wazoku-spotlight/ve-py3/bin/mypy --show-column-numbers /home/w0rp/git/wazoku/wazoku-spotlight/central/models/__init__.py) | grep ^central/models/__init__.p
|
|
|
|
|
|
|
|
function! ale_linters#python#mypy#GetExecutable(buffer) abort
|
|
|
|
if !ale#Var(a:buffer, 'python_mypy_use_global')
|
|
|
|
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
|
2016-12-30 19:06:49 -05:00
|
|
|
|
2017-04-15 20:24:08 -04:00
|
|
|
function! ale_linters#python#mypy#GetCommand(buffer) abort
|
2017-05-06 18:19:54 -04:00
|
|
|
let l:project_root = ale#python#FindProjectRoot(a:buffer)
|
|
|
|
let l:cd_command = !empty(l:project_root)
|
|
|
|
\ ? ale#path#CdString(l:project_root)
|
2017-01-20 12:30:23 -05:00
|
|
|
\ : ''
|
2017-05-06 18:19:54 -04:00
|
|
|
let l:executable = ale_linters#python#mypy#GetExecutable(a:buffer)
|
2017-01-20 12:30:23 -05:00
|
|
|
|
2017-05-06 18:19:54 -04:00
|
|
|
return l:cd_command
|
|
|
|
\ . fnameescape(l:executable)
|
|
|
|
\ . ' --show-column-numbers '
|
2017-04-15 20:24:08 -04:00
|
|
|
\ . ale#Var(a:buffer, 'python_mypy_options')
|
2017-05-06 18:19:54 -04:00
|
|
|
\ . ' %s'
|
2016-12-30 19:06:49 -05:00
|
|
|
endfunction
|
|
|
|
|
2017-04-15 20:24:08 -04:00
|
|
|
function! ale_linters#python#mypy#Handle(buffer, lines) abort
|
2017-01-20 12:30:23 -05:00
|
|
|
" Look for lines like the following:
|
|
|
|
"
|
|
|
|
" file.py:4: error: No library stub file for module 'django.db'
|
|
|
|
"
|
|
|
|
" Lines like these should be ignored below:
|
|
|
|
"
|
|
|
|
" file.py:4: note: (Stub files are from https://github.com/python/typeshed)
|
2017-05-06 18:19:54 -04:00
|
|
|
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?: (error|warning): (.+)$'
|
2017-01-20 12:30:23 -05:00
|
|
|
let l:output = []
|
2017-05-06 18:19:54 -04:00
|
|
|
let l:buffer_filename = expand('#' . a:buffer . ':p')
|
2017-01-20 12:30:23 -05:00
|
|
|
|
2017-04-17 19:35:53 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-05-06 18:19:54 -04:00
|
|
|
if l:buffer_filename[-len(l:match[1]):] !=# l:match[1]
|
2017-01-20 12:30:23 -05:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, {
|
2017-05-06 18:19:54 -04:00
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
|
|
|
\ 'type': l:match[4] =~# 'error' ? 'E' : 'W',
|
|
|
|
\ 'text': l:match[5],
|
2017-01-20 12:30:23 -05:00
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
2017-04-15 08:35:54 -04:00
|
|
|
call ale#linter#Define('python', {
|
2016-12-30 19:06:49 -05:00
|
|
|
\ 'name': 'mypy',
|
2017-05-06 18:19:54 -04:00
|
|
|
\ 'executable_callback': 'ale_linters#python#mypy#GetExecutable',
|
2016-12-30 19:06:49 -05:00
|
|
|
\ 'command_callback': 'ale_linters#python#mypy#GetCommand',
|
2017-01-20 12:30:23 -05:00
|
|
|
\ 'callback': 'ale_linters#python#mypy#Handle',
|
2017-05-06 18:19:54 -04:00
|
|
|
\ 'lint_file': 1,
|
2016-12-30 19:06:49 -05:00
|
|
|
\})
|