Skip to main content

Reorder import statements in Python files

Project description

travis-badge codecov-badge readthedocs-badge pypi-badge

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

Updating AUTHORS, ChangeLog

Source distribution:

$ python setup.py sdist

Binary distribution:

$ python setup.py bdist

Wheels:

$ python setup.py bdist_wheel

Universal Wheels:

python setup.py bdist_wheel --universal

Update the dependencies for tests

$ pip-compile test-requirements.in

Generating the documentation

$ python setup.py docs

Release and upload to Pypi

  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fiximports-0.1.8.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

fiximports-0.1.8-py2.py3-none-any.whl (18.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file fiximports-0.1.8.tar.gz.

File metadata

  • Download URL: fiximports-0.1.8.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fiximports-0.1.8.tar.gz
Algorithm Hash digest
SHA256 147dab4b11710ffbd613189a9c08c58a6021f3e2ebba2ef4448eea0586f22c3b
MD5 f996dc021c0e037f525f71543ebe0645
BLAKE2b-256 91562a5be4142940d6a1983d5c7835ca2ba52467e9bec1632f522551f81c7b34

See more details on using hashes here.

File details

Details for the file fiximports-0.1.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for fiximports-0.1.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6e6bd3d2145ae604d88338aeba0c54c581cc262a588a755129f89241a6842145
MD5 644e8c8c294e485f3cc565be78e167b4
BLAKE2b-256 12f0852879e8fbdec38631fe9baec19478338ffdcecd94de4ed6f666c4018a76

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page