Reorder import statements in Python files
Project description
Python Fix Imports is a Python executable that can automatically reorganize the import statements of your Python script, by splitting single import statement importing several package into as many import statement as imported module (“one import, one line” principle), and sorting these import statements respecting position of group of them.
The main advantage for this method is to strictly restrict the forms of import statement and facilitate multiple code branch merges and rebase, while still allowing to specify a given order if it is the wish of the developer.
Please read the full rational online documenation for more information.
Sublime Text 3 users can use my Python Fix Imports plugin.
Example
Fix imports allows you to automatically turn:
from any_module import d, f
from other_module import z, x
from any_module import (b,
e)
from any_module import a, \
c,
from a_module_that_should_be import at, after, all_others
into:
from any_module import a
from any_module import b
from any_module import c
from any_module import d
from any_module import e
from any_module import f
from other_module import x
from other_module import z
from a_module_that_should_be import after
from a_module_that_should_be import all_others
from a_module_that_should_be import at
Fiximport installation
$ pip install fiximports
Development environment
$ virtualenv env
$ source env/bin/activate
$ pip install --upgrade -e .
$ pip install -r test-requirements.txt
$ python setup.py --version
Executing tests
$ python setup.py test
Update the dependencies for tests
$ pip-compile test-requirements.in
Generating the documentation
$ python setup.py docs
Release and upload to Pypi
Here is the manual release procedure.
Commit everything localy
Create the release tag
git tag 0.?.?
Create you source distribution to regenerate ChangeLog properly
$ python setup.py sdist
Overwrite the release tag
git tag --force 0.?.?
Push to Github, create a release with the same tag
Build source and distribution:
$ rm -rfv dist/* $ python setup.py bdist $ python setup.py bdist_wheel $ python setup.py bdist_wheel --universal
Upload distributions:
$ twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fiximports-0.1.10.tar.gz
.
File metadata
- Download URL: fiximports-0.1.10.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f140b32319a67c2313c23f627afc709f888df3281687f6c4b09d783233eb3b7 |
|
MD5 | f2d431b27344c5950a414fa86712536a |
|
BLAKE2b-256 | 1e0f5bdfd0e4c2f8a023919ccb51437b9cfab947521d891585a6d8c4e146cd2d |
File details
Details for the file fiximports-0.1.10-py2.py3-none-any.whl
.
File metadata
- Download URL: fiximports-0.1.10-py2.py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83fa3379cf24b7318a39c8325dcc72975b7ef04807c988b8f232118c2001ba3c |
|
MD5 | ccd4743ffb4a89839fd5ebe803d2cd86 |
|
BLAKE2b-256 | fc37545bcbfe28c94bf6ea31586fbd552f719e1e45e8e01053675cfbbee90e57 |