]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/fixers/pyflyby.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / fixers / pyflyby.vim
1 " Author: infokiller <joweill@icloud.com>
2 " Description: Tidy imports using pyflyby's tidy-import script
3 " https://github.com/deshaw/pyflyby
4
5 call ale#Set('python_pyflyby_executable', 'tidy-imports')
6 call ale#Set('python_pyflyby_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_pyflyby_options', '')
8 call ale#Set('python_pyflyby_auto_pipenv', 0)
9 call ale#Set('python_pyflyby_auto_poetry', 0)
10 call ale#Set('python_pyflyby_auto_uv', 0)
11
12 function! ale#fixers#pyflyby#GetExecutable(buffer) abort
13     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyflyby_auto_pipenv'))
14     \ && ale#python#PipenvPresent(a:buffer)
15         return 'pipenv'
16     endif
17
18     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyflyby_auto_poetry'))
19     \ && ale#python#PoetryPresent(a:buffer)
20         return 'poetry'
21     endif
22
23     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pyflyby_auto_uv'))
24     \ && ale#python#UvPresent(a:buffer)
25         return 'uv'
26     endif
27
28     return ale#python#FindExecutable(a:buffer, 'python_pyflyby', ['tidy-imports'])
29 endfunction
30
31 function! ale#fixers#pyflyby#Fix(buffer) abort
32     " let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer)
33     let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer)
34     let l:cmd = [ale#Escape(l:executable)]
35
36     if l:executable =~? '\(pipenv\|poetry\|uv\)$'
37         call extend(l:cmd, ['run', 'tidy-imports'])
38     endif
39
40     let l:options = ale#Var(a:buffer, 'python_pyflyby_options')
41
42     if !empty(l:options)
43         call add(l:cmd, l:options)
44     endif
45
46     return {'command': join(l:cmd, ' ')}
47 endfunction