I'm collaborating on Django and the modules are imported in alphabetical order, separated by standard library, third party, and oleore modules! When I was told, I was looking for something like gofmt from golang that would do it for me.
https://github.com/timothycrosley/isort
Very easy to deploy
$ pip install isort
After installation with
$ isort spam.py
So, it sorts and overwrites it. Let's do it before committing.
You can change the behavior by creating a configuration file ~ / .isort.cfg.
isort.cfg
[settings]
line_length=120
multi_line_output=3
It allows up to 120 characters per line and sets the line feed method when importing multiple lines. In this case, if 120 characters are exceeded, a line break will occur as shown below.
from third_party import (
lib1,
lib2,
lib3,
lib4,
)
Click here if you want to do it on Vim instead of the shell
https://github.com/fisadev/vim-isort
If you are using NeoBundle etc., just write it in vimrc.
vimrc
NeoBundle 'fisadev/vim-isort'
This will sort by : Isort
in command mode or<C-i>
in visual mode by selecting the line you want to sort.
Recommended Posts