diff options
author | Horacio Sanson <hsanson@gmail.com> | 2021-01-08 10:43:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-08 10:43:34 +0900 |
commit | 54dd731cf14c809ebcc9c21b41084a17c5411744 (patch) | |
tree | 39ec4ab0d7ad9b3f9062add164a1914d07c6af49 | |
parent | 4c454c96a9d142475b155a94cc24fad34eca26b2 (diff) | |
parent | ce3d891bed18f610beb9117518ef560871ef00a0 (diff) | |
download | ale-54dd731cf14c809ebcc9c21b41084a17c5411744.zip |
Merge pull request #3386 from ivorpeles/master
Make isort fixer recognize auto_pipenv flag
-rw-r--r-- | autoload/ale/fixers/isort.vim | 27 | ||||
-rw-r--r-- | doc/ale-python.txt | 9 | ||||
-rw-r--r-- | test/fixers/test_isort_fixer_callback.vader | 10 |
3 files changed, 38 insertions, 8 deletions
diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 9070fb27..55bb550e 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -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) + + let l:exec_args = l:executable =~? 'pipenv$' + \ ? ' run isort' + \ : '' - if !executable(l:executable) + 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 diff --git a/doc/ale-python.txt b/doc/ale-python.txt index f0c8bfb8..504705f2 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -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* diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 7f389dcf..3941f6dd 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -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('')) |