Skip to main content

Flake8 and pylama plugin that checks the ordering of import statements.

Project description

Build Status

A flake8 and 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. 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 style.

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

  • cryptography - see an example

  • google - style described in Google Style Guidelines, see an example

  • smarkets - style as google only with import statements before from X import … statements, see an example

  • 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

  • pep8 - style that only enforces groups without enforcing the order within the groups

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 style, 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.

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

flake8-import-order-0.10.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

flake8_import_order-0.10-py2.py3-none-any.whl (13.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file flake8-import-order-0.10.tar.gz.

File metadata

File hashes

Hashes for flake8-import-order-0.10.tar.gz
Algorithm Hash digest
SHA256 64ec1220b4755c6bdecffbdbb4c10e6e74f1f7a248c70bbcc33c06d475757d8d
MD5 2ce3b767bc72b152abc3be1f149d1b41
BLAKE2b-256 967475a7248e541bab9698dd3c9c112975faf2194943611f5a2e75d45b6e6002

See more details on using hashes here.

Provenance

File details

Details for the file flake8_import_order-0.10-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_import_order-0.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d5c6cca653b7d3d505c97456d213c5d2eb57ff6f28dcda0f69db63a84b72d956
MD5 ff4c483a885ee4432d8fbc8fbfade52e
BLAKE2b-256 69c18e9449a258fcbbe62c261a941ea268b638187bb038b26e3c8e83af1b8654

See more details on using hashes here.

Provenance

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