All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Fixing Python imports with isort.
4 call ale#Set('python_isort_executable', 'isort')
5 call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0))
6 call ale#Set('python_isort_options', '')
7 call ale#Set('python_isort_auto_pipenv', 0)
8 call ale#Set('python_isort_auto_poetry', 0)
9 call ale#Set('python_isort_auto_uv', 0)
11 function! ale#fixers#isort#GetExecutable(buffer) abort
12 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_isort_auto_pipenv'))
13 \ && ale#python#PipenvPresent(a:buffer)
17 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_isort_auto_poetry'))
18 \ && ale#python#PoetryPresent(a:buffer)
22 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_isort_auto_uv'))
23 \ && ale#python#UvPresent(a:buffer)
27 return ale#python#FindExecutable(a:buffer, 'python_isort', ['isort'])
30 function! ale#fixers#isort#GetCmd(buffer) abort
31 let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
32 let l:cmd = [ale#Escape(l:executable)]
34 if l:executable =~? '\(pipenv\|poetry\|uv\)$'
35 call extend(l:cmd, ['run', 'isort'])
38 return join(l:cmd, ' ')
41 function! ale#fixers#isort#FixForVersion(buffer, version) abort
42 let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
43 let l:cmd = [ale#Escape(l:executable)]
45 if l:executable =~? '\(pipenv\|poetry\|uv\)$'
46 call extend(l:cmd, ['run', 'isort'])
49 if ale#semver#GTE(a:version, [5, 7, 0])
50 call add(l:cmd, '--filename %s')
53 let l:options = ale#Var(a:buffer, 'python_isort_options')
56 call add(l:cmd, l:options)
63 \ 'command': join(l:cmd, ' '),
67 function! ale#fixers#isort#Fix(buffer) abort
68 let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
69 let l:command = ale#fixers#isort#GetCmd(a:buffer) . ale#Pad('--version')
71 return ale#semver#RunWithVersionCheck(
75 \ function('ale#fixers#isort#FixForVersion'),