#729 - Support running Python programs from virtualenv for Windows

This commit is contained in:
w0rp 2017-07-05 13:07:55 +01:00
parent 1b8450e7a0
commit a04e73ddbc
7 changed files with 11 additions and 29 deletions

View File

@ -19,16 +19,8 @@ function! s:UsingModule(buffer) abort
endfunction endfunction
function! ale_linters#python#flake8#GetExecutable(buffer) abort function! ale_linters#python#flake8#GetExecutable(buffer) abort
if !s:UsingModule(a:buffer) && !ale#Var(a:buffer, 'python_flake8_use_global') if !s:UsingModule(a:buffer)
let l:virtualenv = ale#python#FindVirtualenv(a:buffer) return ale#python#FindExecutable(a:buffer, 'python_flake8', ['flake8'])
if !empty(l:virtualenv)
let l:ve_flake8 = l:virtualenv . '/bin/flake8'
if executable(l:ve_flake8)
return l:ve_flake8
endif
endif
endif endif
return ale#Var(a:buffer, 'python_flake8_executable') return ale#Var(a:buffer, 'python_flake8_executable')

View File

@ -7,7 +7,7 @@ let g:ale_python_mypy_options = get(g:, 'ale_python_mypy_options', '')
let g:ale_python_mypy_use_global = get(g:, 'ale_python_mypy_use_global', 0) let g:ale_python_mypy_use_global = get(g:, 'ale_python_mypy_use_global', 0)
function! ale_linters#python#mypy#GetExecutable(buffer) abort function! ale_linters#python#mypy#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_mypy', ['/bin/mypy']) return ale#python#FindExecutable(a:buffer, 'python_mypy', ['mypy'])
endfunction endfunction
function! ale_linters#python#mypy#GetCommand(buffer) abort function! ale_linters#python#mypy#GetCommand(buffer) abort

View File

@ -10,19 +10,7 @@ let g:ale_python_pylint_options =
let g:ale_python_pylint_use_global = get(g:, 'ale_python_pylint_use_global', 0) let g:ale_python_pylint_use_global = get(g:, 'ale_python_pylint_use_global', 0)
function! ale_linters#python#pylint#GetExecutable(buffer) abort function! ale_linters#python#pylint#GetExecutable(buffer) abort
if !ale#Var(a:buffer, 'python_pylint_use_global') return ale#python#FindExecutable(a:buffer, 'python_pylint', ['pylint'])
let l:virtualenv = ale#python#FindVirtualenv(a:buffer)
if !empty(l:virtualenv)
let l:ve_pylint = l:virtualenv . '/bin/pylint'
if executable(l:ve_pylint)
return l:ve_pylint
endif
endif
endif
return ale#Var(a:buffer, 'python_pylint_executable')
endfunction endfunction
function! ale_linters#python#pylint#GetCommand(buffer) abort function! ale_linters#python#pylint#GetCommand(buffer) abort

View File

@ -9,7 +9,7 @@ function! ale#fixers#autopep8#Fix(buffer) abort
let l:executable = ale#python#FindExecutable( let l:executable = ale#python#FindExecutable(
\ a:buffer, \ a:buffer,
\ 'python_autopep8', \ 'python_autopep8',
\ ['/bin/autopep8'], \ ['autopep8'],
\) \)
if !executable(l:executable) if !executable(l:executable)

View File

@ -8,7 +8,7 @@ function! ale#fixers#isort#Fix(buffer) abort
let l:executable = ale#python#FindExecutable( let l:executable = ale#python#FindExecutable(
\ a:buffer, \ a:buffer,
\ 'python_isort', \ 'python_isort',
\ ['/bin/isort'], \ ['isort'],
\) \)
if !executable(l:executable) if !executable(l:executable)

View File

@ -8,7 +8,7 @@ function! ale#fixers#yapf#Fix(buffer) abort
let l:executable = ale#python#FindExecutable( let l:executable = ale#python#FindExecutable(
\ a:buffer, \ a:buffer,
\ 'python_yapf', \ 'python_yapf',
\ ['/bin/yapf'], \ ['yapf'],
\) \)
if !executable(l:executable) if !executable(l:executable)

View File

@ -1,6 +1,8 @@
" Author: w0rp <devw0rp@gmail.com> " Author: w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with Python linters. " Description: Functions for integrating with Python linters.
" 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', [ let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
\ '.env', \ '.env',
\ 'env', \ 'env',
@ -29,7 +31,7 @@ function! ale#python#FindVirtualenv(buffer) abort
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 = simplify(l:path . '/' . l:dirname) let l:venv_dir = simplify(l:path . '/' . l:dirname)
if filereadable(l:venv_dir . '/bin/activate') if filereadable(simplify(l:venv_dir . '/' . s:bin_dir . '/activate'))
return l:venv_dir return l:venv_dir
endif endif
endfor endfor
@ -50,7 +52,7 @@ 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 = l:virtualenv . l:path let l:ve_executable = simplify(l:virtualenv . '/' . s:bin_dir . '/' . l:path)
if executable(l:ve_executable) if executable(l:ve_executable)
return l:ve_executable return l:ve_executable