Merge pull request #3386 from ivorpeles/master

Make isort fixer recognize auto_pipenv flag
This commit is contained in:
Horacio Sanson 2021-01-08 10:43:34 +09:00 committed by GitHub
commit 54dd731cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 8 deletions

View File

@ -2,24 +2,35 @@
" Description: Fixing Python imports with 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_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
let l:options = ale#Var(a:buffer, 'python_isort_options')
let l:executable = ale#python#FindExecutable(
\ a:buffer,
\ 'python_isort',
\ ['isort'],
\)
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
if !executable(l:executable)
let l:exec_args = l:executable =~? 'pipenv$'
\ ? ' run isort'
\ : ''
if !executable(l:executable) && l:executable isnot# 'pipenv'
return 0
endif
return {
\ '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

View File

@ -280,6 +280,15 @@ g:ale_python_isort_use_global *g:ale_python_isort_use_global*
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*

View File

@ -5,6 +5,7 @@ Before:
" Use an invalid global executable, so we don't match it.
let g:ale_python_isort_executable = 'xxxinvalid'
let g:ale_python_isort_options = ''
let g:ale_python_isort_auto_pipenv = 0
call ale#test#SetDirectory('/testplugin/test/fixers')
silent cd ..
@ -48,3 +49,12 @@ Execute(The isort callback should respect custom options):
\ . ' --multi-line=3 --trailing-comma -',
\ },
\ 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(''))