Improve support for python package manage: pipenv, poetry and uv (#4825)
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--neovim-06-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled

This commit is contained in:
Diego Henrique Oliveira
2024-09-05 03:37:30 -03:00
committed by GitHub
parent 954682108d
commit a7ef1817b7
68 changed files with 1156 additions and 125 deletions

View File

@@ -18,22 +18,6 @@ After:
call ale#test#RestoreDirectory()
Execute(The autoflake callback should return the correct default values):
AssertEqual
\ 0,
\ ale#fixers#autoflake#Fix(bufnr(''))
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {
\ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/autoflake'))
\ . ' --in-place '
\ . ' %t',
\ 'read_temporary_file': 1,
\ },
\ ale#fixers#autoflake#Fix(bufnr(''))
Execute(The autoflake callback should include options):
let g:ale_python_autoflake_options = '--some-option'
@@ -47,3 +31,39 @@ Execute(The autoflake callback should include options):
\ 'read_temporary_file': 1,
\ },
\ ale#fixers#autoflake#Fix(bufnr(''))
Execute(pipenv is detected when python_autoflake_auto_pipenv is set):
let g:ale_python_autoflake_auto_pipenv = 1
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('pipenv') . ' run autoflake --in-place %t',
\ 'read_temporary_file': 1,
\ },
\ ale#fixers#autoflake#Fix(bufnr(''))
Execute(Poetry is detected when python_autoflake_auto_poetry is set):
let g:ale_python_autoflake_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('poetry') . ' run autoflake --in-place %t',
\ 'read_temporary_file': 1,
\ },
\ ale#fixers#autoflake#Fix(bufnr(''))
Execute(uv is detected when python_autoflake_auto_uv is set):
let g:ale_python_autoflake_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('uv') . ' run autoflake --in-place %t',
\ 'read_temporary_file': 1,
\ },
\ ale#fixers#autoflake#Fix(bufnr(''))

View File

@@ -18,11 +18,8 @@ After:
call ale#test#RestoreDirectory()
Execute(The autoimport callback should return the correct default values):
AssertEqual
\ 0,
\ ale#fixers#autoimport#Fix(bufnr(''))
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {
\ 'cwd': '%s:h',
@@ -33,11 +30,8 @@ Execute(The autoimport callback should return the correct default values):
Execute(The autoimport callback should respect custom options):
let g:ale_python_autoimport_options = '--multi-line=3 --trailing-comma'
AssertEqual
\ 0,
\ ale#fixers#autoimport#Fix(bufnr(''))
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {
\ 'cwd': '%s:h',
@@ -45,3 +39,39 @@ Execute(The autoimport callback should respect custom options):
\ . ' --multi-line=3 --trailing-comma -',
\ },
\ ale#fixers#autoimport#Fix(bufnr(''))
Execute(pipenv is detected when python_autoimport_auto_pipenv is set):
let g:ale_python_autoimport_auto_pipenv = 1
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertEqual
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('pipenv') . ' run autoimport -',
\ },
\ ale#fixers#autoimport#Fix(bufnr(''))
Execute(Poetry is detected when python_autoimport_auto_poetry is set):
let g:ale_python_autoimport_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertEqual
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('poetry') . ' run autoimport -',
\ },
\ ale#fixers#autoimport#Fix(bufnr(''))
Execute(uv is detected when python_autoimport_auto_uv is set):
let g:ale_python_autoimport_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
AssertEqual
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('uv') . ' run autoimport -',
\ },
\ ale#fixers#autoimport#Fix(bufnr(''))

View File

@@ -19,11 +19,8 @@ After:
call ale#test#RestoreDirectory()
Execute(The autopep8 callback should return the correct default values):
AssertEqual
\ 0,
\ ale#fixers#autopep8#Fix(bufnr(''))
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/autopep8')) . ' -'},
\ ale#fixers#autopep8#Fix(bufnr(''))
@@ -32,6 +29,40 @@ Execute(The autopep8 callback should include options):
let g:ale_python_autopep8_options = '--some-option'
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/autopep8')) . ' --some-option -' },
\ ale#fixers#autopep8#Fix(bufnr(''))
Execute(pipenv is detected when python_autopep8_auto_pipenv is set):
let g:ale_python_autopep8_auto_pipenv = 1
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('pipenv') . ' run autopep8 -',
\ },
\ ale#fixers#autopep8#Fix(bufnr(''))
Execute(Poetry is detected when python_autopep8_auto_poetry is set):
let g:ale_python_autopep8_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('poetry') . ' run autopep8 -',
\ },
\ ale#fixers#autopep8#Fix(bufnr(''))
Execute(uv is detected when python_autopep8_auto_uv is set):
let g:ale_python_autopep8_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('uv') . ' run autopep8 -',
\ },
\ ale#fixers#autopep8#Fix(bufnr(''))

View File

@@ -65,3 +65,13 @@ Execute(Poetry is detected when python_black_auto_poetry is set):
AssertEqual
\ {'command': ale#Escape('poetry') . ' run black -'},
\ ale#fixers#black#Fix(bufnr(''))
Execute(uv is detected when python_black_auto_uv is set):
let g:ale_python_black_auto_uv = 1
let g:ale_python_black_change_directory = 0
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
AssertEqual
\ {'command': ale#Escape('uv') . ' run black -'},
\ ale#fixers#black#Fix(bufnr(''))

View File

@@ -58,6 +58,19 @@ Execute(Poetry is detected when python_isort_auto_poetry is set):
\ 'command': ale#Escape('poetry') . ' run isort' . ' --filename %s' . ' -'
\ }
Execute(uv is detected when python_isort_auto_uv is set):
let g:ale_python_isort_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
GivenCommandOutput ['VERSION 5.7.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('uv') . ' run isort' . ' --filename %s' . ' -'
\ }
Execute(The isort callback should not use --filename for older versions):
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')

View File

@@ -106,6 +106,19 @@ Execute(Poetry is detected when python_pycln_auto_poetry is set, and cwd respect
\ 'command': ale#Escape('poetry') . ' run pycln' . b:cmd_tail . ' -'
\ }
Execute(uv is detected when python_pycln_auto_uv is set):
let g:ale_python_pycln_auto_uv = 1
let g:ale_python_pycln_change_directory = 0
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
GivenCommandOutput ['pycln, version 1.3.0']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('uv') . ' run pycln' . b:cmd_tail . ' -'
\ }
Execute(configuration files set in _config should be supported):
let g:ale_python_pycln_change_directory = 0
let g:ale_python_pycln_config_file = ale#path#Simplify(g:dir . '/../test-files/pycln/other_config.xml')

View File

@@ -36,3 +36,14 @@ Execute(Poetry is detected when python_pyflyby_auto_poetry is set):
\ {
\ 'command': ale#Escape('poetry') . ' run tidy-imports'
\ }
Execute(uv is detected when python_pyflyby_auto_uv is set):
let g:ale_python_pyflyby_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
GivenCommandOutput ['VERSION 5.7.0']
AssertFixer
\ {
\ 'command': ale#Escape('uv') . ' run tidy-imports'
\ }

View File

@@ -18,11 +18,8 @@ After:
call ale#test#RestoreDirectory()
Execute(The reorder_python_imports callback should return the correct default values):
AssertEqual
\ 0,
\ ale#fixers#reorder_python_imports#Fix(bufnr(''))
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {
\ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/'
@@ -33,14 +30,44 @@ Execute(The reorder_python_imports callback should return the correct default va
Execute(The reorder_python_imports callback should respect custom options):
let g:ale_python_reorder_python_imports_options = '--py3-plus'
AssertEqual
\ 0,
\ ale#fixers#reorder_python_imports#Fix(bufnr(''))
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {
\ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/'
\ . b:bin_dir . '/reorder-python-imports')) . ' --py3-plus -',
\ },
\ ale#fixers#reorder_python_imports#Fix(bufnr(''))
Execute(pipenv is detected when python_reorder_python_imports_auto_pipenv is set):
let g:ale_python_reorder_python_imports_auto_pipenv = 1
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('pipenv') . ' run reorder-python-imports -',
\ },
\ ale#fixers#reorder_python_imports#Fix(bufnr(''))
Execute(Poetry is detected when python_reorder_python_imports_auto_poetry is set):
let g:ale_python_reorder_python_imports_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('poetry') . ' run reorder-python-imports -',
\ },
\ ale#fixers#reorder_python_imports#Fix(bufnr(''))
Execute(uv is detected when python_reorder_python_imports_auto_uv is set):
let g:ale_python_reorder_python_imports_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('uv') . ' run reorder-python-imports -',
\ },
\ ale#fixers#reorder_python_imports#Fix(bufnr(''))

View File

@@ -134,3 +134,17 @@ Execute(Poetry is detected when python_ruff_auto_poetry is set, and cwd respects
\ 'command': ale#Escape('poetry') . ' run ruff --stdin-filename ' . fname . ' --fix -'
\ }
Execute(uv is detected when python_ruff_auto_uv is set):
let g:ale_python_ruff_auto_uv = 1
let g:ale_python_ruff_change_directory = 0
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
let fname = ale#Escape(ale#path#Simplify(g:dir .'/../test-files/python/uv/whatever.py'))
GivenCommandOutput ['ruff 0.0.72']
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('uv') . ' run ruff --stdin-filename ' . fname . ' --fix -'
\ }

View File

@@ -84,3 +84,16 @@ Execute(Poetry is detected when python_ruff_format_auto_poetry is set, and cwd r
\ 'command': ale#Escape('poetry') . ' run ruff format --stdin-filename ' . fname . ' -'
\ }
Execute(uv is detected when python_ruff_format_auto_uv is set):
let g:ale_python_ruff_format_auto_uv = 1
let g:ale_python_ruff_format_change_directory = 0
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
let fname = ale#Escape(ale#path#Simplify(g:dir .'/../test-files/python/uv/whatever.py'))
AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('uv') . ' run ruff format --stdin-filename ' . fname . ' -'
\ }

View File

@@ -15,17 +15,6 @@ After:
call ale#test#RestoreDirectory()
Execute(The yapf callback should return the correct default values):
AssertEqual
\ 0,
\ ale#fixers#yapf#Fix(bufnr(''))
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
AssertEqual
\ {'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/yapf'))},
\ ale#fixers#yapf#Fix(bufnr(''))
\
Execute(The yapf should include the .style.yapf file if present):
call ale#test#SetFilename('../test-files/python/with_virtualenv/dir_with_yapf_config/foo/bar.py')
@@ -37,3 +26,36 @@ Execute(The yapf should include the .style.yapf file if present):
\ . ' --style ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/dir_with_yapf_config/.style.yapf')),
\ },
\ ale#fixers#yapf#Fix(bufnr(''))
Execute(pipenv is detected when python_yapf_auto_pipenv is set):
let g:ale_python_yapf_auto_pipenv = 1
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('pipenv') . ' run yapf',
\ },
\ ale#fixers#yapf#Fix(bufnr(''))
Execute(Poetry is detected when python_yapf_auto_poetry is set):
let g:ale_python_yapf_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('poetry') . ' run yapf',
\ },
\ ale#fixers#yapf#Fix(bufnr(''))
Execute(uv is detected when python_yapf_auto_uv is set):
let g:ale_python_yapf_auto_uv = 1
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
AssertEqual
\ {
\ 'command': ale#Escape('uv') . ' run yapf',
\ },
\ ale#fixers#yapf#Fix(bufnr(''))