Support pylama for python (#2266)

* Add pylama for python
* Consolidate python traceback handling
This commit is contained in:
Kevin Locke
2019-02-08 21:44:34 +00:00
committed by w0rp
parent 422908a572
commit a24f0b4d5f
13 changed files with 577 additions and 22 deletions

View File

@@ -27,6 +27,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
\|| filereadable(l:path . '/pycodestyle.cfg')
\|| filereadable(l:path . '/flake8.cfg')
\|| filereadable(l:path . '/.flake8rc')
\|| filereadable(l:path . '/pylama.ini')
\|| filereadable(l:path . '/Pipfile')
\|| filereadable(l:path . '/Pipfile.lock')
return l:path
@@ -110,6 +111,44 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction
" Handle traceback.print_exception() output starting in the first a:limit lines.
function! ale#python#HandleTraceback(lines, limit) abort
let l:nlines = len(a:lines)
let l:limit = a:limit > l:nlines ? l:nlines : a:limit
let l:start = 0
while l:start < l:limit
if a:lines[l:start] is# 'Traceback (most recent call last):'
break
endif
let l:start += 1
endwhile
if l:start >= l:limit
return []
endif
let l:end = l:start + 1
" Traceback entries are always prefixed with 2 spaces.
" SyntaxError marker (if present) is prefixed with at least 4 spaces.
" Final exc line starts with exception class name (never a space).
while l:end < l:nlines && a:lines[l:end][0] is# ' '
let l:end += 1
endwhile
let l:exc_line = l:end < l:nlines
\ ? a:lines[l:end]
\ : 'An exception was thrown.'
return [{
\ 'lnum': 1,
\ 'text': l:exc_line . ' (See :ALEDetail)',
\ 'detail': join(a:lines[(l:start):(l:end)], "\n"),
\}]
endfunction
" Detects whether a pipenv environment is present.
function! ale#python#PipenvPresent(buffer) abort
return findfile('Pipfile.lock', expand('#' . a:buffer . ':p:h') . ';') isnot# ''