mirror of
https://github.com/dense-analysis/ale.git
synced 2026-08-12 02:42:30 +08:00
Merge pull request #2302 from kevinoid/pylint-cd-proj-root
python/pylint: Change directory to project root
This commit is contained in:
@@ -17,9 +17,17 @@ function! ale_linters#python#pylint#GetExecutable(buffer) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#python#pylint#GetCommand(buffer) abort
|
function! ale_linters#python#pylint#GetCommand(buffer) abort
|
||||||
let l:cd_string = ale#Var(a:buffer, 'python_pylint_change_directory')
|
let l:cd_string = ''
|
||||||
\ ? ale#path#BufferCdString(a:buffer)
|
|
||||||
\ : ''
|
if ale#Var(a:buffer, 'python_pylint_change_directory')
|
||||||
|
" pylint only checks for pylintrc in the packages above its current
|
||||||
|
" directory before falling back to user and global pylintrc.
|
||||||
|
" Run from project root, if found, otherwise buffer dir.
|
||||||
|
let l:project_root = ale#python#FindProjectRoot(a:buffer)
|
||||||
|
let l:cd_string = l:project_root isnot# ''
|
||||||
|
\ ? ale#path#CdString(l:project_root)
|
||||||
|
\ : ale#path#BufferCdString(a:buffer)
|
||||||
|
endif
|
||||||
|
|
||||||
let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer)
|
let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer)
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ function! ale#python#FindProjectRootIni(buffer) abort
|
|||||||
\|| filereadable(l:path . '/flake8.cfg')
|
\|| filereadable(l:path . '/flake8.cfg')
|
||||||
\|| filereadable(l:path . '/.flake8rc')
|
\|| filereadable(l:path . '/.flake8rc')
|
||||||
\|| filereadable(l:path . '/pylama.ini')
|
\|| filereadable(l:path . '/pylama.ini')
|
||||||
|
\|| filereadable(l:path . '/pylintrc')
|
||||||
|
\|| filereadable(l:path . '/.pylintrc')
|
||||||
\|| filereadable(l:path . '/Pipfile')
|
\|| filereadable(l:path . '/Pipfile')
|
||||||
\|| filereadable(l:path . '/Pipfile.lock')
|
\|| filereadable(l:path . '/Pipfile.lock')
|
||||||
return l:path
|
return l:path
|
||||||
|
|||||||
+8
-4
@@ -32,6 +32,8 @@ ALE will look for configuration files with the following filenames. >
|
|||||||
flake8.cfg
|
flake8.cfg
|
||||||
.flake8rc
|
.flake8rc
|
||||||
pylama.ini
|
pylama.ini
|
||||||
|
pylintrc
|
||||||
|
.pylintrc
|
||||||
Pipfile
|
Pipfile
|
||||||
Pipfile.lock
|
Pipfile.lock
|
||||||
<
|
<
|
||||||
@@ -512,10 +514,12 @@ g:ale_python_pylint_change_directory *g:ale_python_pylint_change_directory*
|
|||||||
Type: |Number|
|
Type: |Number|
|
||||||
Default: `1`
|
Default: `1`
|
||||||
|
|
||||||
If set to `1`, ALE will switch to the directory the Python file being
|
If set to `1`, `pylint` will be run from a detected project root, per
|
||||||
checked with `pylint` is in before checking it. This helps `pylint` find
|
|ale-python-root|. Since `pylint` only checks for `pylintrc` in the packages
|
||||||
configuration files more easily. This option can be turned off if you want
|
above its current directory before falling back to user and global `pylintrc`
|
||||||
to control the directory Python is executed from yourself.
|
files, this is necessary for `pylint` to use a project `pylintrc` file, if
|
||||||
|
present. This option can be turned off if you want to control the directory
|
||||||
|
Python is executed from yourself.
|
||||||
|
|
||||||
|
|
||||||
g:ale_python_pylint_executable *g:ale_python_pylint_executable*
|
g:ale_python_pylint_executable *g:ale_python_pylint_executable*
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Execute(The pylint callbacks shouldn't detect virtualenv directories where they
|
|||||||
silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py')
|
silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
AssertLinter 'pylint',
|
AssertLinter 'pylint',
|
||||||
\ ale#path#BufferCdString(bufnr(''))
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/no_virtualenv/subdir'))
|
||||||
\ . ale#Escape('pylint') . ' ' . b:command_tail
|
\ . ale#Escape('pylint') . ' ' . b:command_tail
|
||||||
|
|
||||||
Execute(The pylint callbacks should detect virtualenv directories):
|
Execute(The pylint callbacks should detect virtualenv directories):
|
||||||
@@ -50,7 +50,7 @@ Execute(The pylint callbacks should detect virtualenv directories):
|
|||||||
\)
|
\)
|
||||||
|
|
||||||
AssertLinter b:executable,
|
AssertLinter b:executable,
|
||||||
\ ale#path#BufferCdString(bufnr(''))
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir'))
|
||||||
\ . ale#Escape(b:executable) . ' ' . b:command_tail
|
\ . ale#Escape(b:executable) . ' ' . b:command_tail
|
||||||
|
|
||||||
Execute(You should able able to use the global pylint instead):
|
Execute(You should able able to use the global pylint instead):
|
||||||
@@ -58,7 +58,7 @@ Execute(You should able able to use the global pylint instead):
|
|||||||
let g:ale_python_pylint_use_global = 1
|
let g:ale_python_pylint_use_global = 1
|
||||||
|
|
||||||
AssertLinter 'pylint',
|
AssertLinter 'pylint',
|
||||||
\ ale#path#BufferCdString(bufnr(''))
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir'))
|
||||||
\ . ale#Escape('pylint') . ' ' . b:command_tail
|
\ . ale#Escape('pylint') . ' ' . b:command_tail
|
||||||
|
|
||||||
Execute(Setting executable to 'pipenv' appends 'run pylint'):
|
Execute(Setting executable to 'pipenv' appends 'run pylint'):
|
||||||
|
|||||||
Reference in New Issue
Block a user