summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-10-01 18:47:54 +0100
committerw0rp <devw0rp@gmail.com>2017-10-01 18:47:54 +0100
commit638ca4208232ab7abe46efa5052403e58dcfc35a (patch)
treef64eec30956a9813ba10a829c55c9d65ec1da9d1
parent4634b1be93adbeb1cbed2b9f25025b45d0c5015b (diff)
downloadale-638ca4208232ab7abe46efa5052403e58dcfc35a.zip
Use local versions of yapf on Windows, and get the callback tests to pass
-rw-r--r--autoload/ale/fixers/yapf.vim2
-rw-r--r--autoload/ale/python.vim25
-rw-r--r--test/fixers/test_yapf_fixer_callback.vader10
3 files changed, 27 insertions, 10 deletions
diff --git a/autoload/ale/fixers/yapf.vim b/autoload/ale/fixers/yapf.vim
index ba7453b8..b15e481e 100644
--- a/autoload/ale/fixers/yapf.vim
+++ b/autoload/ale/fixers/yapf.vim
@@ -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
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index ed5064d5..4f14697c 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -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)
-
- if filereadable(ale#path#Simplify(l:venv_dir . '/' . s:bin_dir . '/activate'))
+ 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(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
diff --git a/test/fixers/test_yapf_fixer_callback.vader b/test/fixers/test_yapf_fixer_callback.vader
index 6edc2678..e6075568 100644
--- a/test/fixers/test_yapf_fixer_callback.vader
+++ b/test/fixers/test_yapf_fixer_callback.vader
@@ -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(''))