Use local versions of yapf on Windows, and get the callback tests to pass
This commit is contained in:
parent
4634b1be93
commit
638ca42082
@ -11,7 +11,7 @@ function! ale#fixers#yapf#Fix(buffer) abort
|
|||||||
\ ['yapf'],
|
\ ['yapf'],
|
||||||
\)
|
\)
|
||||||
|
|
||||||
if !executable(l:executable)
|
if !ale#python#IsExecutable(l:executable)
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
" Author: w0rp <devw0rp@gmail.com>
|
" Author: w0rp <devw0rp@gmail.com>
|
||||||
" Description: Functions for integrating with Python linters.
|
" Description: Functions for integrating with Python linters.
|
||||||
|
|
||||||
|
let s:sep = has('win32') ? '\' : '/'
|
||||||
" bin is used for Unix virtualenv directories, and Scripts is for Windows.
|
" bin is used for Unix virtualenv directories, and Scripts is for Windows.
|
||||||
let s:bin_dir = has('unix') ? 'bin' : 'Scripts'
|
let s:bin_dir = has('unix') ? 'bin' : 'Scripts'
|
||||||
let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
|
let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
|
||||||
@ -11,7 +12,6 @@ let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
|
|||||||
\ 'virtualenv',
|
\ 'virtualenv',
|
||||||
\])
|
\])
|
||||||
|
|
||||||
|
|
||||||
function! ale#python#FindProjectRootIni(buffer) abort
|
function! ale#python#FindProjectRootIni(buffer) abort
|
||||||
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
|
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
|
||||||
if filereadable(l:path . '/MANIFEST.in')
|
if filereadable(l:path . '/MANIFEST.in')
|
||||||
@ -58,9 +58,14 @@ function! ale#python#FindVirtualenv(buffer) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names')
|
for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names')
|
||||||
let l:venv_dir = ale#path#Simplify(l:path . '/' . l:dirname)
|
let l:venv_dir = ale#path#Simplify(
|
||||||
|
\ join([l:path, l:dirname], s:sep)
|
||||||
|
\)
|
||||||
|
let l:script_filename = ale#path#Simplify(
|
||||||
|
\ join([l:venv_dir, s:bin_dir, 'activate'], s:sep)
|
||||||
|
\)
|
||||||
|
|
||||||
if filereadable(ale#path#Simplify(l:venv_dir . '/' . s:bin_dir . '/activate'))
|
if filereadable(l:script_filename)
|
||||||
return l:venv_dir
|
return l:venv_dir
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@ -69,6 +74,12 @@ function! ale#python#FindVirtualenv(buffer) abort
|
|||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Run an executable check for Python scripts.
|
||||||
|
" On Windows, 1 will be returned if the file is merely readable.
|
||||||
|
function! ale#python#IsExecutable(path) abort
|
||||||
|
return has('win32') ? filereadable(a:path) : executable(a:path)
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Given a buffer number and a command name, find the path to the executable.
|
" Given a buffer number and a command name, find the path to the executable.
|
||||||
" First search on a virtualenv for Python, if nothing is found, try the global
|
" First search on a virtualenv for Python, if nothing is found, try the global
|
||||||
" command. Returns an empty string if cannot find the executable
|
" command. Returns an empty string if cannot find the executable
|
||||||
@ -81,9 +92,11 @@ function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
|
|||||||
|
|
||||||
if !empty(l:virtualenv)
|
if !empty(l:virtualenv)
|
||||||
for l:path in a:path_list
|
for l:path in a:path_list
|
||||||
let l:ve_executable = ale#path#Simplify(l:virtualenv . '/' . s:bin_dir . '/' . l:path)
|
let l:ve_executable = ale#path#Simplify(
|
||||||
|
\ join([l:virtualenv, s:bin_dir, l:path], s:sep)
|
||||||
|
\)
|
||||||
|
|
||||||
if executable(l:ve_executable)
|
if ale#python#IsExecutable(l:ve_executable)
|
||||||
return l:ve_executable
|
return l:ve_executable
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
@ -9,9 +9,13 @@ Before:
|
|||||||
silent cd command_callback
|
silent cd command_callback
|
||||||
let g:dir = getcwd()
|
let g:dir = getcwd()
|
||||||
|
|
||||||
|
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
|
||||||
|
|
||||||
After:
|
After:
|
||||||
Restore
|
Restore
|
||||||
|
|
||||||
|
unlet! b:bin_dir
|
||||||
|
|
||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
Execute(The yapf callback should return the correct default values):
|
Execute(The yapf callback should return the correct default values):
|
||||||
@ -22,7 +26,7 @@ Execute(The yapf callback should return the correct default values):
|
|||||||
call ale#test#SetFilename('python_paths/with_virtualenv/subdir/foo/bar.py')
|
call ale#test#SetFilename('python_paths/with_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {'command': ale#Escape(g:dir . '/python_paths/with_virtualenv/env/bin/yapf')},
|
\ {'command': ale#Escape(ale#path#Winify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/yapf'))},
|
||||||
\ ale#fixers#yapf#Fix(bufnr(''))
|
\ ale#fixers#yapf#Fix(bufnr(''))
|
||||||
\
|
\
|
||||||
Execute(The yapf should include the .style.yapf file if present):
|
Execute(The yapf should include the .style.yapf file if present):
|
||||||
@ -31,8 +35,8 @@ Execute(The yapf should include the .style.yapf file if present):
|
|||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'command':
|
\ 'command':
|
||||||
\ ale#Escape(g:dir . '/python_paths/with_virtualenv/env/bin/yapf')
|
\ ale#Escape(ale#path#Winify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/yapf'))
|
||||||
\ . ' --no-local-style'
|
\ . ' --no-local-style'
|
||||||
\ . ' --style ' . ale#Escape(g:dir . '/python_paths/with_virtualenv/dir_with_yapf_config/.style.yapf'),
|
\ . ' --style ' . ale#Escape(ale#path#Winify(g:dir . '/python_paths/with_virtualenv/dir_with_yapf_config/.style.yapf')),
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#yapf#Fix(bufnr(''))
|
\ ale#fixers#yapf#Fix(bufnr(''))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user