Use local versions of yapf on Windows, and get the callback tests to pass

This commit is contained in:
w0rp 2017-10-01 18:47:54 +01:00
parent 4634b1be93
commit 638ca42082
3 changed files with 26 additions and 9 deletions

View file

@ -11,7 +11,7 @@ function! ale#fixers#yapf#Fix(buffer) abort
\ ['yapf'],
\)
if !executable(l:executable)
if !ale#python#IsExecutable(l:executable)
return 0
endif

View file

@ -1,6 +1,7 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with Python linters.
let s:sep = has('win32') ? '\' : '/'
" bin is used for Unix virtualenv directories, and Scripts is for Windows.
let s:bin_dir = has('unix') ? 'bin' : 'Scripts'
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',
\])
function! ale#python#FindProjectRootIni(buffer) abort
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
if filereadable(l:path . '/MANIFEST.in')
@ -58,9 +58,14 @@ function! ale#python#FindVirtualenv(buffer) abort
endif
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
endif
endfor
@ -69,6 +74,12 @@ function! ale#python#FindVirtualenv(buffer) abort
return ''
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.
" First search on a virtualenv for Python, if nothing is found, try the global
" 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)
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
endif
endfor

View file

@ -9,9 +9,13 @@ Before:
silent cd command_callback
let g:dir = getcwd()
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
After:
Restore
unlet! b:bin_dir
call ale#test#RestoreDirectory()
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')
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(''))
\
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
\ {
\ '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'
\ . ' --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(''))