mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-16 01:07:06 +08:00
Support pylama for python (#2266)
* Add pylama for python * Consolidate python traceback handling
This commit is contained in:
@@ -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# ''
|
||||
|
||||
Reference in New Issue
Block a user