Skip to main content

Reorder import statements in Python files

Project description

******************
Python Fix Imports
******************

|travis-badge|_ |codecov-badge|_ |readthedocs-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 <http://fiximports.readthedocs.org/en/latest/>`_.

Sublime Text 3 users can use my
`Python Fix Imports<https://packagecontrol.io/packages/Python%20Fix%20Imports>`_ plugin.

Example
=======

Fix imports allows you to automatically turn:

.. code:: python

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:

.. code:: python

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
======================

.. code-block:: bash

$ pip install fiximports

Development environment
=======================

.. code-block:: bash

$ virtualenv env
$ source env/bin/activate
$ pip install --upgrade -e .
$ pip install -r test-requirements.txt
$ python setup.py --version

Executing tests
===============

.. code-block:: bash

$ python setup.py test

Updating AUTHORS, ChangeLog
===========================

Source distribution:

.. code-block:: bash

$ python setup.py sdist

Binary distribution:

.. code-block:: bash

$ python setup.py bdist

Wheels:

.. code-block:: bash

$ python setup.py bdist_wheel

Universal Wheels:

.. code-block:: bash

python setup.py bdist_wheel --universal

Update the dependencies for tests
=================================

.. code-block:: bash

$ pip-compile test-requirements.in

.. note::

We do "`pin`_" the dependencies for test environment. We do not "`pin`_ " for development.

.. _pin: http://nvie.com/posts/better-package-management/

Generating the documentation
============================

.. code-block:: bash

$ python setup.py docs

Release and upload to Pypi
==========================

- Commit everything localy

- Create the release tag

.. code-block:: bash

git tag 0.?.?

- Create you source distribution to regenerate ChangeLog properly

.. code-block:: bash

$ python setup.py sdist

- Overwrite the release tag

.. code-block:: bash

git tag --force 0.?.?

- Push to Github, create a release with the same tag

- Build source and distribution:

.. code-block:: bash

$ rm -rfv dist/*
$ python setup.py bdist
$ python setup.py bdist_wheel
$ python setup.py bdist_wheel --universal

- Upload distributions:

.. code-block:: bash

$ twine upload dist/*


.. |travis-badge| image:: https://travis-ci.org/Stibbons/fiximports.svg?branch=master
.. _travis-badge: https://travis-ci.org/Stibbons/fiximports
.. |codecov-badge| image:: http://codecov.io/github/Stibbons/fiximports/coverage.svg?branch=master
.. _codecov-badge: http://codecov.io/github/Stibbons/fiximports?branch=master
.. |readthedocs-badge| image:: https://readthedocs.org/projects/fiximports/badge/?version=latest
.. _readthedocs-badge: https://readthedocs.org/projects/fiximports/builds/

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.7.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

fiximports-0.1.7-py2.py3-none-any.whl (18.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for fiximports-0.1.7.tar.gz
Algorithm Hash digest
SHA256 9216f16d1d9158e808a6cecd83299d4089c7035250f721f961da3a0a803c8125
MD5 76594c0673762bd99c7c208461bac8e3
BLAKE2b-256 69cc378bc659686c29957e27ff62e10bda1dd775c8e0268dfa8e8c6cfe0db10c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fiximports-0.1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5cb4088a4508080ed9c821d621b45683d4bdd07c9c50157a344f95c15ccf2952
MD5 67b1e1de222c2d63ca763dce2cf54cc8
BLAKE2b-256 b92423ea23d46490dc63de52830d6d7edacce77f1c8dd3b88fc1501208786496

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