Fix #1566 - Add g:ale_python_flake8_change_directory

This commit is contained in:
w0rp 2018-05-28 16:34:54 +01:00
parent d9717147bf
commit 8a659b7cc6
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
3 changed files with 28 additions and 7 deletions

View File

@ -1,14 +1,13 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: flake8 for python files
let g:ale_python_flake8_executable =
\ get(g:, 'ale_python_flake8_executable', 'flake8')
" Support an old setting as a fallback.
let s:default_options = get(g:, 'ale_python_flake8_args', '')
let g:ale_python_flake8_options =
\ get(g:, 'ale_python_flake8_options', s:default_options)
let g:ale_python_flake8_use_global = get(g:, 'ale_python_flake8_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('python_flake8_executable', 'flake8')
call ale#Set('python_flake8_options', s:default_options)
call ale#Set('python_flake8_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('python_flake8_change_directory', 1)
function! s:UsingModule(buffer) abort
return ale#Var(a:buffer, 'python_flake8_options') =~# ' *-m flake8'
@ -39,7 +38,9 @@ function! ale_linters#python#flake8#VersionCheck(buffer) abort
endfunction
function! ale_linters#python#flake8#GetCommand(buffer, version_output) abort
let l:cd_string = ale#path#BufferCdString(a:buffer)
let l:cd_string = ale#Var(a:buffer, 'python_flake8_change_directory')
\ ? ale#path#BufferCdString(a:buffer)
\ : ''
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
let l:version = ale#semver#GetVersion(l:executable, a:version_output)

View File

@ -59,6 +59,17 @@ g:ale_python_black_use_global *g:ale_python_black_use_global*
===============================================================================
flake8 *ale-python-flake8*
g:ale_python_flake8_change_directory *g:ale_python_flake8_change_directory*
*b:ale_python_flake8_change_directory*
Type: |Number|
Default: `1`
If set to `1`, ALE will switch to the directory the Python file being
checked with `flake8` is in before checking it. This helps `flake8` find
configuration files more easily. This option can be turned off if you want
to control the directory Python is executed from yourself.
g:ale_python_flake8_executable *g:ale_python_flake8_executable*
*b:ale_python_flake8_executable*
Type: |String|

View File

@ -2,11 +2,13 @@ Before:
Save g:ale_python_flake8_executable
Save g:ale_python_flake8_options
Save g:ale_python_flake8_use_global
Save g:ale_python_flake8_change_directory
unlet! g:ale_python_flake8_executable
unlet! g:ale_python_flake8_args
unlet! g:ale_python_flake8_options
unlet! g:ale_python_flake8_use_global
unlet! g:ale_python_flake8_change_directory
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
@ -44,6 +46,13 @@ Execute(The flake8 callbacks should return the correct default values):
\ . ale#Escape('flake8') . ' --format=default -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['2.9.9'])
Execute(The option for disabling changing directories should work):
let g:ale_python_flake8_change_directory = 0
AssertEqual
\ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['3.0.0'])
Execute(The flake8 command callback should let you set options):
let g:ale_python_flake8_options = '--some-option'