mirror of https://github.com/dense-analysis/ale
Merge pull request #2262 from sectioneight/cd-for-black
Respect python black fixer configuration file
This commit is contained in:
commit
ba6f08f3d4
|
@ -5,6 +5,7 @@ call ale#Set('python_black_executable', 'black')
|
||||||
call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0))
|
call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
call ale#Set('python_black_options', '')
|
call ale#Set('python_black_options', '')
|
||||||
call ale#Set('python_black_auto_pipenv', 0)
|
call ale#Set('python_black_auto_pipenv', 0)
|
||||||
|
call ale#Set('python_black_change_directory', 1)
|
||||||
|
|
||||||
function! ale#fixers#black#GetExecutable(buffer) abort
|
function! ale#fixers#black#GetExecutable(buffer) abort
|
||||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv'))
|
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv'))
|
||||||
|
@ -16,6 +17,10 @@ function! ale#fixers#black#GetExecutable(buffer) abort
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#black#Fix(buffer) abort
|
function! ale#fixers#black#Fix(buffer) abort
|
||||||
|
let l:cd_string = ale#Var(a:buffer, 'python_black_change_directory')
|
||||||
|
\ ? ale#path#BufferCdString(a:buffer)
|
||||||
|
\ : ''
|
||||||
|
|
||||||
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
|
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
|
||||||
|
|
||||||
let l:exec_args = l:executable =~? 'pipenv$'
|
let l:exec_args = l:executable =~? 'pipenv$'
|
||||||
|
@ -25,7 +30,7 @@ function! ale#fixers#black#Fix(buffer) abort
|
||||||
let l:options = ale#Var(a:buffer, 'python_black_options')
|
let l:options = ale#Var(a:buffer, 'python_black_options')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable) . l:exec_args
|
\ 'command': l:cd_string . ale#Escape(l:executable) . l:exec_args
|
||||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
\ . ' -',
|
\ . ' -',
|
||||||
\}
|
\}
|
||||||
|
|
|
@ -139,6 +139,16 @@ g:ale_python_black_auto_pipenv *g:ale_python_black_auto_pipenv*
|
||||||
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
|
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
|
||||||
if true. This is overridden by a manually-set executable.
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
g:ale_python_black_change_directory *g:ale_python_black_change_directory*
|
||||||
|
*b:ale_python_black_change_directory*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `1`
|
||||||
|
|
||||||
|
If set to `1`, ALE will switch to the directory the Python file being
|
||||||
|
checked with `black` is in before checking it. This helps `black` find
|
||||||
|
configuration files more easily. This option can be turned off if you want
|
||||||
|
to control the directory Python is executed from yourself.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
flake8 *ale-python-flake8*
|
flake8 *ale-python-flake8*
|
||||||
|
|
|
@ -24,11 +24,12 @@ After:
|
||||||
Execute(The black callback should return the correct default values):
|
Execute(The black callback should return the correct default values):
|
||||||
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
|
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {'command': ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/black')) . ' -'},
|
\ {'command': ale#path#BufferCdString(bufnr('')) . ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/black')) . ' -'},
|
||||||
\ ale#fixers#black#Fix(bufnr(''))
|
\ ale#fixers#black#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The black callback should include options):
|
Execute(The black callback should include options):
|
||||||
let g:ale_python_black_options = '--some-option'
|
let g:ale_python_black_options = '--some-option'
|
||||||
|
let g:ale_python_black_change_directory = 0
|
||||||
|
|
||||||
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
|
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
|
@ -37,8 +38,10 @@ Execute(The black callback should include options):
|
||||||
|
|
||||||
Execute(Pipenv is detected when python_black_auto_pipenv is set):
|
Execute(Pipenv is detected when python_black_auto_pipenv is set):
|
||||||
let g:ale_python_black_auto_pipenv = 1
|
let g:ale_python_black_auto_pipenv = 1
|
||||||
|
let g:ale_python_black_change_directory = 0
|
||||||
|
|
||||||
call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py')
|
call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {'command': ale#Escape('pipenv') . ' run black -'},
|
\ {'command': ale#Escape('pipenv') . ' run black -'},
|
||||||
\ ale#fixers#black#Fix(bufnr(''))
|
\ ale#fixers#black#Fix(bufnr(''))
|
||||||
|
|
Loading…
Reference in New Issue