Use flake8-import-order plugin

In reviews we usually check import grouping but it is boring.
By using flake8-import-order plugin, we can avoid this.
It enforces loose checking so it sounds good to use it.
This flake8 plugin is already used in tempest.

Note that flake8-import-order version is pinned to avoid unexpected
breakage of pep8 job.

Setup for unit tests of hacking rules is tweaked to disable
flake8-import-order checks. This extension assumes an actual file exists
and causes hacking rule unit tests.

Change-Id: Ib51bd97dc4394ef2b46d4dbb7fb36a9aa9f8fe3d
This commit is contained in:
Akihiro Motoki 2017-07-02 11:07:42 +00:00
parent 9d20de62bf
commit f64110f652
30 changed files with 39 additions and 24 deletions

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
import collections import collections
import netaddr import netaddr
from neutron_lib import constants as lib_constants from neutron_lib import constants as lib_constants
from neutron_lib.utils import helpers from neutron_lib.utils import helpers

View File

@ -13,7 +13,6 @@
# under the License. # under the License.
import abc import abc
import six
from neutron_lib.api import converters from neutron_lib.api import converters
from neutron_lib.api.definitions import provider_net as providernet from neutron_lib.api.definitions import provider_net as providernet
@ -21,6 +20,7 @@ from neutron_lib.api import extensions as api_extensions
from neutron_lib import constants from neutron_lib import constants
from neutron_lib.db import constants as db_const from neutron_lib.db import constants as db_const
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes from neutron.api.v2 import attributes

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
from collections import defaultdict from collections import defaultdict
from neutron_lib.plugins import constants as lib_const from neutron_lib.plugins import constants as lib_const
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_config import cfg from oslo_config import cfg

View File

@ -15,9 +15,9 @@
import collections import collections
from operator import itemgetter
from neutron_lib import constants from neutron_lib import constants
from operator import itemgetter
from oslo_config import cfg from oslo_config import cfg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_log import log as logging from oslo_log import log as logging

View File

@ -13,9 +13,9 @@
# under the License. # under the License.
# #
import functools import functools
import netaddr
import fixtures import fixtures
import netaddr
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings
from neutron_lib import constants from neutron_lib import constants
from neutronclient.common import exceptions from neutronclient.common import exceptions

View File

@ -13,10 +13,10 @@
# under the License. # under the License.
import functools import functools
import netaddr
import os import os
import time import time
import netaddr
from oslo_utils import uuidutils from oslo_utils import uuidutils
from neutron.agent.l3 import ha_router from neutron.agent.l3 import ha_router

View File

@ -15,6 +15,7 @@
import copy import copy
import functools import functools
import textwrap
import mock import mock
import netaddr import netaddr
@ -23,7 +24,6 @@ from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import uuidutils from oslo_utils import uuidutils
import testtools import testtools
import textwrap
from neutron.agent.common import ovs_lib from neutron.agent.common import ovs_lib
from neutron.agent.l3 import agent as neutron_l3_agent from neutron.agent.l3 import agent as neutron_l3_agent

View File

@ -17,6 +17,7 @@
# under the License. # under the License.
from __future__ import print_function from __future__ import print_function
import sys import sys
import eventlet import eventlet

View File

@ -14,9 +14,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mock
import time import time
import mock
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources from neutron_lib.callbacks import resources

View File

@ -13,10 +13,11 @@
# under the License. # under the License.
import collections import collections
from contextlib import contextmanager
import subprocess
from alembic.ddl import base as alembic_ddl from alembic.ddl import base as alembic_ddl
from alembic import script as alembic_script from alembic import script as alembic_script
from contextlib import contextmanager
from oslo_config import cfg from oslo_config import cfg
from oslo_config import fixture as config_fixture from oslo_config import fixture as config_fixture
from oslo_db.sqlalchemy import test_migrations from oslo_db.sqlalchemy import test_migrations
@ -25,7 +26,6 @@ import six
import sqlalchemy import sqlalchemy
from sqlalchemy import event # noqa from sqlalchemy import event # noqa
from sqlalchemy.sql import ddl as sqla_ddl from sqlalchemy.sql import ddl as sqla_ddl
import subprocess
from neutron.db.migration.alembic_migrations import external from neutron.db.migration.alembic_migrations import external
from neutron.db.migration import cli as migration from neutron.db.migration import cli as migration

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
import copy import copy
import mock import mock
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import uuidutils from oslo_utils import uuidutils

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mock
import os.path import os.path
import mock
from oslo_utils import fileutils from oslo_utils import fileutils
import psutil import psutil

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import errno import errno
import socket
import mock import mock
import netaddr import netaddr
@ -21,7 +22,6 @@ from neutron_lib import exceptions
import pyroute2 import pyroute2
from pyroute2.netlink.rtnl import ndmsg from pyroute2.netlink.rtnl import ndmsg
from pyroute2 import NetlinkError from pyroute2 import NetlinkError
import socket
import testtools import testtools
from neutron.agent.common import utils # noqa from neutron.agent.common import utils # noqa

View File

@ -14,12 +14,11 @@
# #
import os import os
import mock
import testtools
import textwrap import textwrap
import mock
from neutron_lib import constants as n_consts from neutron_lib import constants as n_consts
import testtools
from neutron.agent.linux import keepalived from neutron.agent.linux import keepalived
from neutron.tests import base from neutron.tests import base

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import datetime import datetime
import mock import mock
from oslo_context import context as oslo_context from oslo_context import context as oslo_context

View File

@ -14,8 +14,8 @@
# limitations under the License. # limitations under the License.
import datetime import datetime
import mock
import mock
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources from neutron_lib.callbacks import resources

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import collections import collections
import mock import mock
from neutron_lib import constants from neutron_lib import constants

View File

@ -16,8 +16,8 @@
import copy import copy
import datetime import datetime
import mock
import mock
from neutron_lib import constants from neutron_lib import constants
from neutron_lib import context from neutron_lib import context
from neutron_lib import exceptions as n_exc from neutron_lib import exceptions as n_exc

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import copy import copy
import mock import mock
import netaddr import netaddr
from neutron_lib import constants from neutron_lib import constants

View File

@ -12,6 +12,7 @@
# limitations under the License. # limitations under the License.
import copy import copy
import mock import mock
from neutron_lib.callbacks import events from neutron_lib.callbacks import events
from neutron_lib.callbacks import exceptions from neutron_lib.callbacks import exceptions

View File

@ -11,8 +11,8 @@
# under the License. # under the License.
import abc import abc
import netaddr
import netaddr
from neutron_lib import context from neutron_lib import context
from oslo_db import exception from oslo_db import exception
from oslo_db.tests.sqlalchemy import base as test_base from oslo_db.tests.sqlalchemy import base as test_base

View File

@ -14,9 +14,9 @@
import copy import copy
import fixtures import fixtures
import mock import mock
from neutron_lib import context from neutron_lib import context
from neutron_lib.db import constants as db_const from neutron_lib.db import constants as db_const
from oslo_config import cfg from oslo_config import cfg

View File

@ -13,8 +13,8 @@
# under the License. # under the License.
import copy import copy
from keystoneauth1 import exceptions as ks_exc
from keystoneauth1 import exceptions as ks_exc
import mock import mock
import netaddr import netaddr
from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import portbindings

View File

@ -13,12 +13,12 @@
# under the License. # under the License.
import datetime import datetime
import six
import mock import mock
from neutron_lib import context from neutron_lib import context
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from neutron.db import db_base_plugin_v2 from neutron.db import db_base_plugin_v2
from neutron.db import models_v2 from neutron.db import models_v2

View File

@ -15,6 +15,7 @@ import re
from flake8 import engine from flake8 import engine
from hacking.tests import test_doctest as hacking_doctest from hacking.tests import test_doctest as hacking_doctest
import pep8 import pep8
import pkg_resources
import testscenarios import testscenarios
import testtools import testtools
from testtools import content from testtools import content
@ -288,10 +289,13 @@ def _get_lines(check):
def load_tests(loader, tests, pattern): def load_tests(loader, tests, pattern):
flake8_style = engine.get_style_guide(parse_argv=False, default_checks = [e.name for e
# Ignore H104 otherwise it's in pkg_resources.iter_entry_points('flake8.extension')]
# raised on doctests. flake8_style = engine.get_style_guide(
ignore=('F', 'H104')) parse_argv=False,
# We are testing neutron-specific hacking rules, so there is no need
# to run the checks registered by hacking or other flake8 extensions.
ignore=default_checks)
options = flake8_style.options options = flake8_style.options
for name, check in checks.__dict__.items(): for name, check in checks.__dict__.items():

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
import datetime import datetime
from oslo_utils import uuidutils from oslo_utils import uuidutils
from neutron.objects import quota from neutron.objects import quota

View File

@ -15,6 +15,7 @@
# under the License. # under the License.
import hashlib import hashlib
import mock import mock
from neutron.plugins.ml2.drivers.macvtap import macvtap_common as m_common from neutron.plugins.ml2.drivers.macvtap import macvtap_common as m_common

View File

@ -14,8 +14,8 @@
# under the License. # under the License.
import contextlib import contextlib
import mock
import mock
import testtools import testtools
from neutron.services.trunk.drivers.openvswitch.agent import trunk_manager from neutron.services.trunk.drivers.openvswitch.agent import trunk_manager

View File

@ -5,6 +5,7 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD fixtures>=3.0.0 # Apache-2.0/BSD
flake8-import-order==0.12 # LGPLv3
mock>=2.0 # BSD mock>=2.0 # BSD
python-subunit>=0.0.18 # Apache-2.0/BSD python-subunit>=0.0.18 # Apache-2.0/BSD
sphinx!=1.6.1,>=1.5.1 # BSD sphinx!=1.6.1,>=1.5.1 # BSD

View File

@ -145,6 +145,7 @@ ignore = E125,E126,E128,E129,E265,H404,H405,N530,N534,N536,N537
enable-extensions=H106,H203,H904 enable-extensions=H106,H203,H904
show-source = true show-source = true
exclude = ./.*,build,dist,doc exclude = ./.*,build,dist,doc
import-order-style = pep8
[hacking] [hacking]
import_exceptions = neutron._i18n import_exceptions = neutron._i18n