forked from github-mirrors/ale
Add pyflyby fixer (using its tidy-imports script) (#4219)
* add pyflyby fixer updates * pyflyby: add docs updates * add tests to pyflyby fixer
This commit is contained in:
parent
f10349b48b
commit
91e8422d6d
|
@ -136,6 +136,11 @@ let s:default_registry = {
|
||||||
\ 'description': 'Apply prettier-eslint to a file.',
|
\ 'description': 'Apply prettier-eslint to a file.',
|
||||||
\ 'aliases': ['prettier-eslint'],
|
\ 'aliases': ['prettier-eslint'],
|
||||||
\ },
|
\ },
|
||||||
|
\ 'pyflyby': {
|
||||||
|
\ 'function': 'ale#fixers#pyflyby#Fix',
|
||||||
|
\ 'suggested_filetypes': ['python'],
|
||||||
|
\ 'description': 'Tidy Python imports with pyflyby.',
|
||||||
|
\ },
|
||||||
\ 'importjs': {
|
\ 'importjs': {
|
||||||
\ 'function': 'ale#fixers#importjs#Fix',
|
\ 'function': 'ale#fixers#importjs#Fix',
|
||||||
\ 'suggested_filetypes': ['javascript'],
|
\ 'suggested_filetypes': ['javascript'],
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
" Author: infokiller <joweill@icloud.com>
|
||||||
|
" Description: Tidy imports using pyflyby's tidy-import script
|
||||||
|
" https://github.com/deshaw/pyflyby
|
||||||
|
|
||||||
|
call ale#Set('python_pyflyby_executable', 'tidy-imports')
|
||||||
|
call ale#Set('python_pyflyby_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
call ale#Set('python_pyflyby_options', '')
|
||||||
|
call ale#Set('python_pyflyby_auto_pipenv', 0)
|
||||||
|
call ale#Set('python_pyflyby_auto_poetry', 0)
|
||||||
|
|
||||||
|
function! ale#fixers#pyflyby#GetExecutable(buffer) abort
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyflyby_auto_pipenv'))
|
||||||
|
\ && ale#python#PipenvPresent(a:buffer)
|
||||||
|
return 'pipenv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyflyby_auto_poetry'))
|
||||||
|
\ && ale#python#PoetryPresent(a:buffer)
|
||||||
|
return 'poetry'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#python#FindExecutable(a:buffer, 'python_pyflyby', ['tidy-imports'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#fixers#pyflyby#Fix(buffer) abort
|
||||||
|
" let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer)
|
||||||
|
let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer)
|
||||||
|
let l:cmd = [ale#Escape(l:executable)]
|
||||||
|
|
||||||
|
if l:executable =~? 'pipenv\|poetry$'
|
||||||
|
call extend(l:cmd, ['run', 'tidy-imports'])
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:options = ale#Var(a:buffer, 'python_pyflyby_options')
|
||||||
|
|
||||||
|
if !empty(l:options)
|
||||||
|
call add(l:cmd, l:options)
|
||||||
|
endif
|
||||||
|
|
||||||
|
return {'command': join(l:cmd, ' ')}
|
||||||
|
endfunction
|
|
@ -708,6 +708,52 @@ g:ale_python_pyflakes_auto_poetry *g:ale_python_pyflakes_auto_poetry*
|
||||||
if true. This is overridden by a manually-set executable.
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
pyflyby *ale-python-pyflyby*
|
||||||
|
|
||||||
|
g:ale_python_pyflyby_executable *g:ale_python_pyflyby_executable*
|
||||||
|
*b:ale_python_pyflyby_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'tidy-imports'`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_python_pyflyby_options *g:ale_python_pyflyby_options*
|
||||||
|
*b:ale_python_pyflyby_options*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be changed to add command-line arguments to the pyflyby
|
||||||
|
tidy-imports invocation.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_python_pyflyby_use_global *g:ale_python_pyflyby_use_global*
|
||||||
|
*b:ale_python_pyflyby_use_global*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `get(g:, 'ale_use_global_executables', 0)`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_python_pyflyby_auto_pipenv *g:ale_python_pyflyby_auto_pipenv*
|
||||||
|
*b:ale_python_pyflyby_auto_pipenv*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
|
||||||
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_python_pyflyby_auto_poetry *g:ale_python_pyflyby_auto_poetry*
|
||||||
|
*b:ale_python_pyflyby_auto_poetry*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a poetry, and set the executable to `poetry`
|
||||||
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
pylama *ale-python-pylama*
|
pylama *ale-python-pylama*
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,7 @@ Notes:
|
||||||
* `pycodestyle`
|
* `pycodestyle`
|
||||||
* `pydocstyle`
|
* `pydocstyle`
|
||||||
* `pyflakes`
|
* `pyflakes`
|
||||||
|
* `pyflyby`
|
||||||
* `pylama`!!
|
* `pylama`!!
|
||||||
* `pylint`!!
|
* `pylint`!!
|
||||||
* `pylsp`
|
* `pylsp`
|
||||||
|
|
|
@ -3117,6 +3117,7 @@ documented in additional help files.
|
||||||
pycodestyle...........................|ale-python-pycodestyle|
|
pycodestyle...........................|ale-python-pycodestyle|
|
||||||
pydocstyle............................|ale-python-pydocstyle|
|
pydocstyle............................|ale-python-pydocstyle|
|
||||||
pyflakes..............................|ale-python-pyflakes|
|
pyflakes..............................|ale-python-pyflakes|
|
||||||
|
pyflyby...............................|ale-python-pyflyby|
|
||||||
pylama................................|ale-python-pylama|
|
pylama................................|ale-python-pylama|
|
||||||
pylint................................|ale-python-pylint|
|
pylint................................|ale-python-pylint|
|
||||||
pylsp.................................|ale-python-pylsp|
|
pylsp.................................|ale-python-pylsp|
|
||||||
|
|
|
@ -475,6 +475,7 @@ formatting.
|
||||||
* [pycodestyle](https://github.com/PyCQA/pycodestyle) :warning:
|
* [pycodestyle](https://github.com/PyCQA/pycodestyle) :warning:
|
||||||
* [pydocstyle](https://www.pydocstyle.org/) :warning:
|
* [pydocstyle](https://www.pydocstyle.org/) :warning:
|
||||||
* [pyflakes](https://github.com/PyCQA/pyflakes)
|
* [pyflakes](https://github.com/PyCQA/pyflakes)
|
||||||
|
* [pyflyby](https://github.com/deshaw/pyflyby) :warning:
|
||||||
* [pylama](https://github.com/klen/pylama) :floppy_disk:
|
* [pylama](https://github.com/klen/pylama) :floppy_disk:
|
||||||
* [pylint](https://www.pylint.org/) :floppy_disk:
|
* [pylint](https://www.pylint.org/) :floppy_disk:
|
||||||
* [pylsp](https://github.com/python-lsp/python-lsp-server) :warning:
|
* [pylsp](https://github.com/python-lsp/python-lsp-server) :warning:
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
Before:
|
||||||
|
call ale#assert#SetUpFixerTest('python', 'pyflyby')
|
||||||
|
|
||||||
|
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownFixerTest()
|
||||||
|
|
||||||
|
unlet! b:bin_dir
|
||||||
|
|
||||||
|
Execute(The pyflyby callback should return the correct default values):
|
||||||
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/tidy-imports')),
|
||||||
|
\ }
|
||||||
|
|
||||||
|
Execute(Pipenv is detected when python_pyflyby_auto_pipenv is set):
|
||||||
|
let g:ale_python_pyflyby_auto_pipenv = 1
|
||||||
|
|
||||||
|
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
|
||||||
|
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('pipenv') . ' run tidy-imports'
|
||||||
|
\ }
|
||||||
|
|
||||||
|
Execute(Poetry is detected when python_pyflyby_auto_poetry is set):
|
||||||
|
let g:ale_python_pyflyby_auto_poetry = 1
|
||||||
|
|
||||||
|
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
|
||||||
|
|
||||||
|
GivenCommandOutput ['VERSION 5.7.0']
|
||||||
|
AssertFixer
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('poetry') . ' run tidy-imports'
|
||||||
|
\ }
|
Loading…
Reference in New Issue