summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorDaniel Roseman <daniel@roseman.org.uk>2021-07-25 05:39:05 +0100
committerGitHub <noreply@github.com>2021-07-25 13:39:05 +0900
commit7d8fb2ba1716a744446b811fc278ecf30d4eb771 (patch)
treecabed5301053216ab424e6f554dc7595b1948bb3 /autoload
parent530b38de342a21cce330a32af0c1b66671d335c2 (diff)
downloadale-7d8fb2ba1716a744446b811fc278ecf30d4eb771.zip
Python support poetry (#3834)
* Add poetry support to python linters and black fixer. * Update python.vim to detect poetry project. * Update ale.vim, add an option for poetry `g:ale_python_auto_poetry`. * Update ale-python.txt, add poetry support. * Add and update poetry related tests. Co-authored-by: unc0 <unc0@users.noreply.github.com>
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fixers/black.vim8
-rw-r--r--autoload/ale/python.vim6
2 files changed, 13 insertions, 1 deletions
diff --git a/autoload/ale/fixers/black.vim b/autoload/ale/fixers/black.vim
index 142cd983..4a88c5cd 100644
--- a/autoload/ale/fixers/black.vim
+++ b/autoload/ale/fixers/black.vim
@@ -5,6 +5,7 @@ call ale#Set('python_black_executable', 'black')
call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('python_black_options', '')
call ale#Set('python_black_auto_pipenv', 0)
+call ale#Set('python_black_auto_poetry', 0)
call ale#Set('python_black_change_directory', 1)
function! ale#fixers#black#GetExecutable(buffer) abort
@@ -13,6 +14,11 @@ function! ale#fixers#black#GetExecutable(buffer) abort
return 'pipenv'
endif
+ if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_black_auto_poetry'))
+ \ && ale#python#PoetryPresent(a:buffer)
+ return 'poetry'
+ endif
+
return ale#python#FindExecutable(a:buffer, 'python_black', ['black'])
endfunction
@@ -20,7 +26,7 @@ function! ale#fixers#black#Fix(buffer) abort
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
- if l:executable =~? 'pipenv$'
+ if l:executable =~? 'pipenv\|poetry$'
call extend(l:cmd, ['run', 'black'])
endif
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index 40433d17..ee856a27 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -2,6 +2,7 @@
" Description: Functions for integrating with Python linters.
call ale#Set('python_auto_pipenv', '0')
+call ale#Set('python_auto_poetry', '0')
let s:sep = has('win32') ? '\' : '/'
" bin is used for Unix virtualenv directories, and Scripts is for Windows.
@@ -158,3 +159,8 @@ endfunction
function! ale#python#PipenvPresent(buffer) abort
return findfile('Pipfile.lock', expand('#' . a:buffer . ':p:h') . ';') isnot# ''
endfunction
+
+" Detects whether a poetry environment is present.
+function! ale#python#PoetryPresent(buffer) abort
+ return findfile('poetry.lock', expand('#' . a:buffer . ':p:h') . ';') isnot# ''
+endfunction