mirror of
https://github.com/dense-analysis/ale.git
synced 2026-05-24 17:28:42 +08:00
Merge pull request #3386 from ivorpeles/master
Make isort fixer recognize auto_pipenv flag
This commit is contained in:
@@ -2,24 +2,35 @@
|
|||||||
" Description: Fixing Python imports with isort.
|
" Description: Fixing Python imports with isort.
|
||||||
|
|
||||||
call ale#Set('python_isort_executable', 'isort')
|
call ale#Set('python_isort_executable', 'isort')
|
||||||
call ale#Set('python_isort_options', '')
|
|
||||||
call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0))
|
call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
call ale#Set('python_isort_options', '')
|
||||||
|
call ale#Set('python_isort_auto_pipenv', 0)
|
||||||
|
|
||||||
|
function! ale#fixers#isort#GetExecutable(buffer) abort
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_isort_auto_pipenv'))
|
||||||
|
\ && ale#python#PipenvPresent(a:buffer)
|
||||||
|
return 'pipenv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#python#FindExecutable(a:buffer, 'python_isort', ['isort'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#isort#Fix(buffer) abort
|
function! ale#fixers#isort#Fix(buffer) abort
|
||||||
let l:options = ale#Var(a:buffer, 'python_isort_options')
|
let l:options = ale#Var(a:buffer, 'python_isort_options')
|
||||||
|
|
||||||
let l:executable = ale#python#FindExecutable(
|
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
|
||||||
\ a:buffer,
|
|
||||||
\ 'python_isort',
|
|
||||||
\ ['isort'],
|
|
||||||
\)
|
|
||||||
|
|
||||||
if !executable(l:executable)
|
let l:exec_args = l:executable =~? 'pipenv$'
|
||||||
|
\ ? ' run isort'
|
||||||
|
\ : ''
|
||||||
|
|
||||||
|
if !executable(l:executable) && l:executable isnot# 'pipenv'
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#path#BufferCdString(a:buffer)
|
\ 'command': ale#path#BufferCdString(a:buffer)
|
||||||
\ . ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') . ' -',
|
\ . ale#Escape(l:executable) . l:exec_args
|
||||||
|
\ . (!empty(l:options) ? ' ' . l:options : '') . ' -',
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -280,6 +280,15 @@ g:ale_python_isort_use_global *g:ale_python_isort_use_global*
|
|||||||
See |ale-integrations-local-executables|
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_python_isort_auto_pipenv *g:ale_python_isort_auto_pipenv*
|
||||||
|
*b:ale_python_isort_auto_pipenv*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
|
||||||
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
mypy *ale-python-mypy*
|
mypy *ale-python-mypy*
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Before:
|
|||||||
" Use an invalid global executable, so we don't match it.
|
" Use an invalid global executable, so we don't match it.
|
||||||
let g:ale_python_isort_executable = 'xxxinvalid'
|
let g:ale_python_isort_executable = 'xxxinvalid'
|
||||||
let g:ale_python_isort_options = ''
|
let g:ale_python_isort_options = ''
|
||||||
|
let g:ale_python_isort_auto_pipenv = 0
|
||||||
|
|
||||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
silent cd ..
|
silent cd ..
|
||||||
@@ -48,3 +49,12 @@ Execute(The isort callback should respect custom options):
|
|||||||
\ . ' --multi-line=3 --trailing-comma -',
|
\ . ' --multi-line=3 --trailing-comma -',
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#isort#Fix(bufnr(''))
|
\ ale#fixers#isort#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Pipenv is detected when python_isort_auto_pipenv is set):
|
||||||
|
let g:ale_python_isort_auto_pipenv = 1
|
||||||
|
|
||||||
|
call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {'command': ale#path#BufferCdString(bufnr('')) . ale#Escape('pipenv') . ' run isort -'},
|
||||||
|
\ ale#fixers#isort#Fix(bufnr(''))
|
||||||
|
|||||||
Reference in New Issue
Block a user