diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim index 2c0c9d8..067b08b 100644 --- a/autoload/ale/python.vim +++ b/autoload/ale/python.vim @@ -1,6 +1,15 @@ " Author: w0rp " Description: Functions for integrating with Python linters. +let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [ +\ '.env', +\ 'env', +\ 've', +\ 've-py3', +\ 'virtualenv', +\]) + + " Given a buffer number, find the project root directory for Python. " The root directory is defined as the first directory found while searching " upwards through paths, including the current directory, until a path @@ -18,11 +27,13 @@ endfunction " Given a buffer number, find a virtualenv path for Python. function! ale#python#FindVirtualenv(buffer) abort for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h')) - let l:matches = globpath(l:path, '*/bin/activate', 0, 1) + for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names') + let l:venv_dir = l:path . '/' . l:dirname - if !empty(l:matches) - return fnamemodify(l:matches[-1], ':h:h') - endif + if filereadable(l:venv_dir . '/bin/activate') + return l:venv_dir + endif + endfor endfor return '' diff --git a/doc/ale-python.txt b/doc/ale-python.txt index 2964671..0a8b708 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -2,6 +2,21 @@ ALE Python Integration *ale-python-options* +------------------------------------------------------------------------------- +Global Options + +g:ale_virtualenv_dir_names *g:ale_virtualenv_dir_names* + *b:ale_virtualenv_dir_names* + + Type: |List| + Default: `['.env', 'env', 've', 've-py3', 'virtualenv']` + + A list of directory names to be used when searching upwards from Python + files to discover virtulenv directories with. For directory named `'foo'`, + ALE will search for `'foo/bin/activate'` in all directories on and above + the directory containing the Python file to find virtualenv paths. + + ------------------------------------------------------------------------------- flake8 *ale-python-flake8*