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 files with black.
4 call ale#Set('python_black_executable', 'black')
5 call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0))
6 call ale#Set('python_black_options', '')
7 call ale#Set('python_black_auto_pipenv', 0)
8 call ale#Set('python_black_auto_poetry', 0)
9 call ale#Set('python_black_auto_uv', 0)
10 call ale#Set('python_black_change_directory', 1)
12 function! ale#fixers#black#GetExecutable(buffer) abort
13 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv'))
14 \ && ale#python#PipenvPresent(a:buffer)
18 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_black_auto_poetry'))
19 \ && ale#python#PoetryPresent(a:buffer)
23 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_black_auto_uv'))
24 \ && ale#python#UvPresent(a:buffer)
28 return ale#python#FindExecutable(a:buffer, 'python_black', ['black'])
31 function! ale#fixers#black#Fix(buffer) abort
32 let l:executable = ale#fixers#black#GetExecutable(a:buffer)
33 let l:cmd = [ale#Escape(l:executable)]
35 if l:executable =~? '\(pipenv\|poetry\|uv\)$'
36 call extend(l:cmd, ['run', 'black'])
39 let l:options = ale#Var(a:buffer, 'python_black_options')
42 call add(l:cmd, l:options)
45 let l:fname = expand('#' . a:buffer . '...')
46 call add(l:cmd, '--stdin-filename '.ale#Escape(ale#path#Simplify(l:fname)))
48 if expand('#' . a:buffer . ':e') is? 'pyi'
49 call add(l:cmd, '--pyi')
54 let l:result = {'command': join(l:cmd, ' ')}
56 if ale#Var(a:buffer, 'python_black_change_directory')
57 let l:result.cwd = '%s:h'