flake8-import-order


Nameflake8-import-order JSON
Version 0.12 PyPI version JSON
download
home_pagehttps://github.com/PyCQA/flake8-import-order
SummaryFlake8 and pylama plugin that checks the ordering of import statements.
upload_time2017-02-11 11:07:40
maintainer
docs_urlNone
authorPhil Jones
requires_python
licenseLGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
Coveralis test coverage No Coveralis.
            flake8-import-order
===================

|Build Status|

A `flake8 <http://flake8.readthedocs.org/en/latest/>`__ and
`Pylama <https://github.com/klen/pylama>`__ plugin that checks the
ordering of your imports.

In general stdlib comes first, then 3rd party, then local packages, and
that each group is individually alphabetized, see Configuration section
for details.

It will not check anything else about the imports. Merely that they are
grouped and ordered correctly.

This plugin is under somewhat active development and is heavily
influenced by the personal preferences of the developers of
`cryptography <https://github.com/pyca/cryptography>`__. Expect
seemingly random changes and configuration changes as we figure out how
it should work.

Warnings
--------

This package adds 3 new flake8 warnings

-  ``I100``: Your import statements are in the wrong order.
-  ``I101``: The names in your from import are in the wrong order.
-  ``I201``: Missing newline between sections or imports.

Configuration
-------------

You will want to set the ``application-import-names`` option to a
comma separated list of names that should be considered local to your
application. These will be used to help categorise your import
statements into the correct groups. Note that relative imports are
always considered local.

You will want to set the ``application-package-names`` option to a
comma separated list of names that should be considered local to your
company or organisation, but which are obtained using some sort of
package manager like Pip, Apt, or Yum.  Typically, code representing the
values listed in this option is located in a different repository than
the code being developed.  This option is only supported if using the
``appnexus`` or ``edited`` styles.

``import-order-style`` controls what style the plugin follows
(``cryptography`` is the default):

* ``cryptography`` - see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_cryptography.py>`__
* ``google`` - style described in `Google Style Guidelines <https://google.github.io/styleguide/pyguide.html?showone=Imports_formatting#Imports_formatting>`__, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_google.py>`__
* ``smarkets`` - style as ``google`` only with `import` statements before `from X import ...` statements, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_smarkets.py>`__
* ``appnexus`` - style as ``google`` only with `import` statements for packages local to your company or organisation coming after `import` statements for third-party packages, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_appnexus.py>`__
* ``edited`` - style as ``smarkets`` only with `import` statements for packages local to your company or organisation coming after `import` statements for third-party packages, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_edited.py>`__
* ``pep8`` - style that only enforces groups without enforcing the order within the groups

You can also `add your own style <#extending-styles>`_ by extending ``Style``
class.

Limitations
-----------

Currently these checks are limited to module scope imports only.
Conditional imports in module scope will also be ignored.

Classification of an imported module is achieved by checking the
module against a stdlib list and then if there is no match against the
``application-import-names`` list. (If using the ``appnexus``  or
``edited`` styles, also the ``application-package-names`` list.) Only if
none of these lists contain the imported module will it be classified as
third party.

``I201`` only checks that groups of imports are not consecutive and only
takes into account the first line of each import statement. This means
that multi-line from imports, comments between imports and so on may
cause this error not to be raised correctly in all situations. This
restriction is due to the data provided by the stdlib ``ast`` module.

Imported modules are classified as stdlib if the module is in a
vendored list of stdlib modules. This list is based on the latest
release of Python and hence the results can be misleading. This list
is also the same for all Python versions because otherwise it would
be impossible to write programs that work under both Python 2 and 3
*and* pass the import order check.

Extending styles
----------------

You can add your own style by extending ``flake8_import_order.styles.Style``
class.  Here's an example:

.. code-block:: python

    from flake8_import_order.styles import Cryptography


    class ReversedCryptography(Cryptography):
        # Note that Cryptography is a subclass of Style.

        @staticmethod
        def sorted_names(names):
            return reversed(Cryptography.sorted_names(names))

To make flake8-import-order able to discover your extended style, you need to
register it as ``flake8_import_order.styles`` using setuptools' `entry points
<https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points>`__
mechanism:

.. code-block:: python

    # setup.py of your style package
    setup(
        name='flake8-import-order-reversed-cryptography',
        ...,
        entry_points={
            'flake8_import_order.styles': [
                'reversed = reversedcryptography:ReversedCryptography',
                # 'reversed' is a style name.  You can pass it to
                # --import-order-style option
                # 'reversedcryptography:ReversedCryptography' is an import path
                # of your extended style class.
            ]
        }
    )

.. |Build Status| image:: https://travis-ci.org/PyCQA/flake8-import-order.png?branch=master
   :target: https://travis-ci.org/PyCQA/flake8-import-order
            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "coveralis": false, 
    "keywords": "", 
    "upload_time": "2017-02-11 11:07:40", 
    "author": "Phil Jones", 
    "home_page": "https://github.com/PyCQA/flake8-import-order", 
    "github_user": "PyCQA", 
    "download_url": "https://pypi.python.org/packages/75/02/4e83dd8502f18aaae88331f9a05a5c2ce034306a47bab59bf8205a1351e6/flake8-import-order-0.12.tar.gz", 
    "platform": "UNKNOWN", 
    "version": "0.12", 
    "cheesecake_documentation_id": null, 
    "description": "flake8-import-order\n===================\n\n|Build Status|\n\nA `flake8 <http://flake8.readthedocs.org/en/latest/>`__ and\n`Pylama <https://github.com/klen/pylama>`__ plugin that checks the\nordering of your imports.\n\nIn general stdlib comes first, then 3rd party, then local packages, and\nthat each group is individually alphabetized, see Configuration section\nfor details.\n\nIt will not check anything else about the imports. Merely that they are\ngrouped and ordered correctly.\n\nThis plugin is under somewhat active development and is heavily\ninfluenced by the personal preferences of the developers of\n`cryptography <https://github.com/pyca/cryptography>`__. Expect\nseemingly random changes and configuration changes as we figure out how\nit should work.\n\nWarnings\n--------\n\nThis package adds 3 new flake8 warnings\n\n-  ``I100``: Your import statements are in the wrong order.\n-  ``I101``: The names in your from import are in the wrong order.\n-  ``I201``: Missing newline between sections or imports.\n\nConfiguration\n-------------\n\nYou will want to set the ``application-import-names`` option to a\ncomma separated list of names that should be considered local to your\napplication. These will be used to help categorise your import\nstatements into the correct groups. Note that relative imports are\nalways considered local.\n\nYou will want to set the ``application-package-names`` option to a\ncomma separated list of names that should be considered local to your\ncompany or organisation, but which are obtained using some sort of\npackage manager like Pip, Apt, or Yum.  Typically, code representing the\nvalues listed in this option is located in a different repository than\nthe code being developed.  This option is only supported if using the\n``appnexus`` or ``edited`` styles.\n\n``import-order-style`` controls what style the plugin follows\n(``cryptography`` is the default):\n\n* ``cryptography`` - see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_cryptography.py>`__\n* ``google`` - style described in `Google Style Guidelines <https://google.github.io/styleguide/pyguide.html?showone=Imports_formatting#Imports_formatting>`__, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_google.py>`__\n* ``smarkets`` - style as ``google`` only with `import` statements before `from X import ...` statements, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_smarkets.py>`__\n* ``appnexus`` - style as ``google`` only with `import` statements for packages local to your company or organisation coming after `import` statements for third-party packages, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_appnexus.py>`__\n* ``edited`` - style as ``smarkets`` only with `import` statements for packages local to your company or organisation coming after `import` statements for third-party packages, see an `example <https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_edited.py>`__\n* ``pep8`` - style that only enforces groups without enforcing the order within the groups\n\nYou can also `add your own style <#extending-styles>`_ by extending ``Style``\nclass.\n\nLimitations\n-----------\n\nCurrently these checks are limited to module scope imports only.\nConditional imports in module scope will also be ignored.\n\nClassification of an imported module is achieved by checking the\nmodule against a stdlib list and then if there is no match against the\n``application-import-names`` list. (If using the ``appnexus``  or\n``edited`` styles, also the ``application-package-names`` list.) Only if\nnone of these lists contain the imported module will it be classified as\nthird party.\n\n``I201`` only checks that groups of imports are not consecutive and only\ntakes into account the first line of each import statement. This means\nthat multi-line from imports, comments between imports and so on may\ncause this error not to be raised correctly in all situations. This\nrestriction is due to the data provided by the stdlib ``ast`` module.\n\nImported modules are classified as stdlib if the module is in a\nvendored list of stdlib modules. This list is based on the latest\nrelease of Python and hence the results can be misleading. This list\nis also the same for all Python versions because otherwise it would\nbe impossible to write programs that work under both Python 2 and 3\n*and* pass the import order check.\n\nExtending styles\n----------------\n\nYou can add your own style by extending ``flake8_import_order.styles.Style``\nclass.  Here's an example:\n\n.. code-block:: python\n\n    from flake8_import_order.styles import Cryptography\n\n\n    class ReversedCryptography(Cryptography):\n        # Note that Cryptography is a subclass of Style.\n\n        @staticmethod\n        def sorted_names(names):\n            return reversed(Cryptography.sorted_names(names))\n\nTo make flake8-import-order able to discover your extended style, you need to\nregister it as ``flake8_import_order.styles`` using setuptools' `entry points\n<https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points>`__\nmechanism:\n\n.. code-block:: python\n\n    # setup.py of your style package\n    setup(\n        name='flake8-import-order-reversed-cryptography',\n        ...,\n        entry_points={\n            'flake8_import_order.styles': [\n                'reversed = reversedcryptography:ReversedCryptography',\n                # 'reversed' is a style name.  You can pass it to\n                # --import-order-style option\n                # 'reversedcryptography:ReversedCryptography' is an import path\n                # of your extended style class.\n            ]\n        }\n    )\n\n.. |Build Status| image:: https://travis-ci.org/PyCQA/flake8-import-order.png?branch=master\n   :target: https://travis-ci.org/PyCQA/flake8-import-order", 
    "tox": true, 
    "lcname": "flake8-import-order", 
    "bugtrack_url": null, 
    "github": true, 
    "name": "flake8-import-order", 
    "license": "LGPLv3", 
    "travis_ci": true, 
    "github_project": "flake8-import-order", 
    "summary": "Flake8 and pylama plugin that checks the ordering of import statements.", 
    "split_keywords": [], 
    "author_email": "philip.graham.jones+flake8-import@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2017-02-11T11:07:40", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/75/02/4e83dd8502f18aaae88331f9a05a5c2ce034306a47bab59bf8205a1351e6/flake8-import-order-0.12.tar.gz", 
            "md5_digest": "95321de1b6464b77d91e41519539420b", 
            "downloads": 0, 
            "filename": "flake8-import-order-0.12.tar.gz", 
            "packagetype": "sdist", 
            "path": "75/02/4e83dd8502f18aaae88331f9a05a5c2ce034306a47bab59bf8205a1351e6/flake8-import-order-0.12.tar.gz", 
            "size": 17912
        }, 
        {
            "has_sig": false, 
            "upload_time": "2017-02-11T11:07:38", 
            "comment_text": "", 
            "python_version": "py2.py3", 
            "url": "https://pypi.python.org/packages/6f/a3/9873a279c4cca791ab0e8fca694aa682bdd3297339254459cd6edfdc58bf/flake8_import_order-0.12-py2.py3-none-any.whl", 
            "md5_digest": "854b36a32ffcb98576ff96e9354755af", 
            "downloads": 0, 
            "filename": "flake8_import_order-0.12-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "6f/a3/9873a279c4cca791ab0e8fca694aa682bdd3297339254459cd6edfdc58bf/flake8_import_order-0.12-py2.py3-none-any.whl", 
            "size": 14708
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}