From 65fbf1cdff316090f404bb65f8c8a54a00551650 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 20 May 2017 13:34:53 +0100 Subject: [PATCH] #563 Use a configurable list of directories for detecting virtualenv paths instead. --- autoload/ale/python.vim | 19 +++++++++++++++---- doc/ale-python.txt | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) 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*