From e6b78f92f2bcc2b1f0986e36124ebadb30f4af8f Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sun, 2 Jul 2017 10:50:06 +0000 Subject: [PATCH] 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. This flake8 plugin is already used in tempest. It enforces loose checking so it sounds good to use. Note that flake8-import-order version is pinned to avoid unexpected breakage of pep8 job. Change-Id: I8ccd05eb70350a2441cc2a4d1eafc09ee690b83b --- doc/source/conf.py | 2 +- horizon/base.py | 2 +- horizon/management/commands/startdash.py | 2 +- horizon/management/commands/startpanel.py | 2 +- horizon/templatetags/horizon.py | 2 +- horizon/test/test_hacking.py | 3 ++- horizon/test/tests/base.py | 9 +++++---- horizon/test/tests/test_file_discovery.py | 4 +++- openstack_dashboard/api/heat.py | 8 ++++---- openstack_dashboard/api/swift.py | 1 + openstack_dashboard/dashboards/admin/volumes/views.py | 1 + .../dashboards/project/security_groups/tests.py | 7 +++---- openstack_dashboard/dashboards/project/volumes/tests.py | 4 ++-- .../management/commands/update_catalog.py | 2 +- openstack_dashboard/templatetags/themes.py | 1 + openstack_dashboard/test/api_tests/cinder_rest_tests.py | 2 +- openstack_dashboard/test/api_tests/heat_rest_tests.py | 1 + openstack_dashboard/test/api_tests/nova_rest_tests.py | 4 ++-- openstack_dashboard/test/helpers.py | 2 +- openstack_dashboard/test/integration_tests/helpers.py | 3 +-- .../test/integration_tests/pages/navigation.py | 2 +- .../project/compute/access_and_security/apiaccesspage.py | 5 +++-- .../test/integration_tests/regions/forms.py | 2 +- .../test/integration_tests/tests/test_credentials.py | 8 ++++---- test-requirements.txt | 1 + tox.ini | 1 + 26 files changed, 45 insertions(+), 36 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index a15a04cbf1..97a6bb1e6c 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -24,11 +24,11 @@ from __future__ import print_function -import django import logging import os import sys +import django # NOTE(amotoki): Sphinx 1.6.x catches warnings from imported modules. # Ignore warnings from openstack_dashboard.settings in the doc build. diff --git a/horizon/base.py b/horizon/base.py index 187186fc24..0b2ef870b6 100644 --- a/horizon/base.py +++ b/horizon/base.py @@ -22,6 +22,7 @@ the classes contained therein. import collections import copy +from importlib import import_module import inspect import logging import os @@ -37,7 +38,6 @@ from django.utils.functional import empty from django.utils.functional import SimpleLazyObject from django.utils.module_loading import module_has_submodule from django.utils.translation import ugettext_lazy as _ -from importlib import import_module import six from horizon import conf diff --git a/horizon/management/commands/startdash.py b/horizon/management/commands/startdash.py index 10a28cdd4b..18f0e3e30b 100644 --- a/horizon/management/commands/startdash.py +++ b/horizon/management/commands/startdash.py @@ -11,11 +11,11 @@ # under the License. import glob +from importlib import import_module import os from django.core.management.base import CommandError from django.core.management.templates import TemplateCommand -from importlib import import_module import horizon diff --git a/horizon/management/commands/startpanel.py b/horizon/management/commands/startpanel.py index 6e36581cb8..5b4904ecd0 100644 --- a/horizon/management/commands/startpanel.py +++ b/horizon/management/commands/startpanel.py @@ -11,11 +11,11 @@ # under the License. import glob +from importlib import import_module import os from django.core.management.base import CommandError from django.core.management.templates import TemplateCommand -from importlib import import_module import horizon diff --git a/horizon/templatetags/horizon.py b/horizon/templatetags/horizon.py index 5721569c6d..5e22734263 100644 --- a/horizon/templatetags/horizon.py +++ b/horizon/templatetags/horizon.py @@ -15,7 +15,6 @@ from __future__ import absolute_import from collections import OrderedDict -from horizon.contrib import bootstrap_datepicker from django.conf import settings from django import template @@ -26,6 +25,7 @@ from django.utils.translation import ugettext_lazy as _ from horizon.base import Horizon from horizon import conf +from horizon.contrib import bootstrap_datepicker register = template.Library() diff --git a/horizon/test/test_hacking.py b/horizon/test/test_hacking.py index e6ec669bde..f8b8fa4d6f 100644 --- a/horizon/test/test_hacking.py +++ b/horizon/test/test_hacking.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +import textwrap + import mock import pep8 -import textwrap from horizon.hacking import checks from horizon.test import helpers diff --git a/horizon/test/tests/base.py b/horizon/test/tests/base.py index 94e612f35d..43aea570d0 100644 --- a/horizon/test/tests/base.py +++ b/horizon/test/tests/base.py @@ -17,15 +17,16 @@ # License for the specific language governing permissions and limitations # under the License. +from importlib import import_module + +import six +from six import moves + import django from django.conf import settings from django.contrib.auth.models import User from django.core.exceptions import ImproperlyConfigured from django.core import urlresolvers -from importlib import import_module -from six import moves - -import six import horizon from horizon import base diff --git a/horizon/test/tests/test_file_discovery.py b/horizon/test/tests/test_file_discovery.py index 3fb0055651..8659003c18 100644 --- a/horizon/test/tests/test_file_discovery.py +++ b/horizon/test/tests/test_file_discovery.py @@ -10,9 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -from horizon.utils import file_discovery as fd import unittest +from horizon.utils import file_discovery as fd + + base_path = 'some_root/fake_static_files/' test_structure = [ diff --git a/openstack_dashboard/api/heat.py b/openstack_dashboard/api/heat.py index 38f554ae21..c31c61dad9 100644 --- a/openstack_dashboard/api/heat.py +++ b/openstack_dashboard/api/heat.py @@ -11,16 +11,16 @@ # under the License. import contextlib -import six -from six.moves.urllib import request from django.conf import settings -from oslo_serialization import jsonutils - from heatclient import client as heat_client from heatclient.common import template_format from heatclient.common import template_utils from heatclient.common import utils as heat_utils +from oslo_serialization import jsonutils +import six +from six.moves.urllib import request + from horizon import exceptions from horizon.utils import functions as utils from horizon.utils.memoized import memoized diff --git a/openstack_dashboard/api/swift.py b/openstack_dashboard/api/swift.py index fc34871a67..b262fb60ae 100644 --- a/openstack_dashboard/api/swift.py +++ b/openstack_dashboard/api/swift.py @@ -17,6 +17,7 @@ # under the License. from datetime import datetime + import six.moves.urllib.parse as urlparse import swiftclient diff --git a/openstack_dashboard/dashboards/admin/volumes/views.py b/openstack_dashboard/dashboards/admin/volumes/views.py index b30b7cf0fb..2a93503404 100644 --- a/openstack_dashboard/dashboards/admin/volumes/views.py +++ b/openstack_dashboard/dashboards/admin/volumes/views.py @@ -16,6 +16,7 @@ Admin views for managing volumes and snapshots. """ from collections import OrderedDict + from django.conf import settings from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse_lazy diff --git a/openstack_dashboard/dashboards/project/security_groups/tests.py b/openstack_dashboard/dashboards/project/security_groups/tests.py index 0e095265cb..ccde979eac 100644 --- a/openstack_dashboard/dashboards/project/security_groups/tests.py +++ b/openstack_dashboard/dashboards/project/security_groups/tests.py @@ -17,6 +17,8 @@ # under the License. import cgi + +from mox3.mox import IsA import six import django @@ -24,17 +26,14 @@ from django.conf import settings from django.core.urlresolvers import reverse from django import http -from mox3.mox import IsA - from horizon import exceptions from horizon import forms from openstack_dashboard import api +from openstack_dashboard.dashboards.project.security_groups import tables from openstack_dashboard.test import helpers as test from openstack_dashboard.usage import quotas -from openstack_dashboard.dashboards.project.security_groups import tables - INDEX_URL = reverse('horizon:project:security_groups:index') SG_CREATE_URL = reverse('horizon:project:security_groups:create') diff --git a/openstack_dashboard/dashboards/project/volumes/tests.py b/openstack_dashboard/dashboards/project/volumes/tests.py index bd97492240..ec3cd33ff1 100644 --- a/openstack_dashboard/dashboards/project/volumes/tests.py +++ b/openstack_dashboard/dashboards/project/volumes/tests.py @@ -13,6 +13,8 @@ # under the License. import copy + +from mox3.mox import IsA import six from six import moves @@ -25,8 +27,6 @@ from django.template.defaultfilters import slugify from django.test.utils import override_settings from django.utils.http import urlunquote -from mox3.mox import IsA - from openstack_dashboard import api from openstack_dashboard.api import cinder from openstack_dashboard.dashboards.project.volumes \ diff --git a/openstack_dashboard/management/commands/update_catalog.py b/openstack_dashboard/management/commands/update_catalog.py index 522dd7f28d..b534029d21 100644 --- a/openstack_dashboard/management/commands/update_catalog.py +++ b/openstack_dashboard/management/commands/update_catalog.py @@ -15,10 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import babel.messages.catalog as catalog import os from subprocess import call +import babel.messages.catalog as catalog from django.conf import settings from django.core.management.base import BaseCommand from django.utils import translation diff --git a/openstack_dashboard/templatetags/themes.py b/openstack_dashboard/templatetags/themes.py index 3f6e01908d..c87555fe55 100644 --- a/openstack_dashboard/templatetags/themes.py +++ b/openstack_dashboard/templatetags/themes.py @@ -16,6 +16,7 @@ from __future__ import absolute_import import os + from six.moves.urllib.request import pathname2url from django.conf import settings diff --git a/openstack_dashboard/test/api_tests/cinder_rest_tests.py b/openstack_dashboard/test/api_tests/cinder_rest_tests.py index 0126bd5221..097d99488a 100644 --- a/openstack_dashboard/test/api_tests/cinder_rest_tests.py +++ b/openstack_dashboard/test/api_tests/cinder_rest_tests.py @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. import json -import mock from django.conf import settings +import mock from openstack_dashboard import api from openstack_dashboard.api.base import Quota diff --git a/openstack_dashboard/test/api_tests/heat_rest_tests.py b/openstack_dashboard/test/api_tests/heat_rest_tests.py index 40d7ed3593..ef5cc0f7c6 100644 --- a/openstack_dashboard/test/api_tests/heat_rest_tests.py +++ b/openstack_dashboard/test/api_tests/heat_rest_tests.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json + import mock from openstack_dashboard import api diff --git a/openstack_dashboard/test/api_tests/nova_rest_tests.py b/openstack_dashboard/test/api_tests/nova_rest_tests.py index bfdf11c7bd..e537262bb3 100644 --- a/openstack_dashboard/test/api_tests/nova_rest_tests.py +++ b/openstack_dashboard/test/api_tests/nova_rest_tests.py @@ -11,10 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import mock +from json import loads as to_json from django.conf import settings -from json import loads as to_json +import mock from openstack_dashboard import api from openstack_dashboard.api.base import Quota diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py index 50a1044af9..24af4faece 100644 --- a/openstack_dashboard/test/helpers.py +++ b/openstack_dashboard/test/helpers.py @@ -19,6 +19,7 @@ import collections import copy from functools import wraps +from importlib import import_module import os import traceback import unittest @@ -35,7 +36,6 @@ from django.utils import http from cinderclient import client as cinder_client import glanceclient from heatclient import client as heat_client -from importlib import import_module from keystoneclient.v2_0 import client as keystone_client import mock from mox3 import mox diff --git a/openstack_dashboard/test/integration_tests/helpers.py b/openstack_dashboard/test/integration_tests/helpers.py index 5671cef354..7841352e94 100644 --- a/openstack_dashboard/test/integration_tests/helpers.py +++ b/openstack_dashboard/test/integration_tests/helpers.py @@ -14,7 +14,6 @@ import contextlib import logging import os import shutil -from six import StringIO import socket import subprocess import tempfile @@ -22,10 +21,10 @@ import time import traceback from oslo_utils import uuidutils - from selenium.webdriver.common import action_chains from selenium.webdriver.common import by from selenium.webdriver.common import keys +from six import StringIO import testtools import xvfbwrapper diff --git a/openstack_dashboard/test/integration_tests/pages/navigation.py b/openstack_dashboard/test/integration_tests/pages/navigation.py index 66ba8323fa..d348a4f7ad 100644 --- a/openstack_dashboard/test/integration_tests/pages/navigation.py +++ b/openstack_dashboard/test/integration_tests/pages/navigation.py @@ -12,9 +12,9 @@ import importlib import json -import six from selenium.webdriver.common import by +import six from openstack_dashboard.test.integration_tests import config diff --git a/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py b/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py index 72f2031eae..be40fc609e 100644 --- a/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py +++ b/openstack_dashboard/test/integration_tests/pages/project/compute/access_and_security/apiaccesspage.py @@ -9,14 +9,15 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from openstack_dashboard.test.integration_tests.pages import basepage -from openstack_dashboard.test.integration_tests.regions import tables from os import listdir from os.path import isfile from os.path import join from re import search +from openstack_dashboard.test.integration_tests.pages import basepage +from openstack_dashboard.test.integration_tests.regions import tables + class ApiAccessTable(tables.TableRegion): name = "endpoints" diff --git a/openstack_dashboard/test/integration_tests/regions/forms.py b/openstack_dashboard/test/integration_tests/regions/forms.py index 6ecc993a49..b7afbbf576 100644 --- a/openstack_dashboard/test/integration_tests/regions/forms.py +++ b/openstack_dashboard/test/integration_tests/regions/forms.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. import collections -import six from selenium.common import exceptions from selenium.webdriver.common import by import selenium.webdriver.support.ui as Support +import six from openstack_dashboard.test.integration_tests.regions import baseregion from openstack_dashboard.test.integration_tests.regions import menus diff --git a/openstack_dashboard/test/integration_tests/tests/test_credentials.py b/openstack_dashboard/test/integration_tests/tests/test_credentials.py index 9c61b39b1f..110a080b76 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_credentials.py +++ b/openstack_dashboard/test/integration_tests/tests/test_credentials.py @@ -10,14 +10,14 @@ # License for the specific language governing permissions and limitations # under the License. -from horizon.test import firefox_binary -from openstack_dashboard.test.integration_tests import decorators -from openstack_dashboard.test.integration_tests import helpers - from os import listdir from os.path import join from os import remove +from horizon.test import firefox_binary +from openstack_dashboard.test.integration_tests import decorators +from openstack_dashboard.test.integration_tests import helpers + class TestDownloadRCFile(helpers.AdminTestCase): diff --git a/test-requirements.txt b/test-requirements.txt index 236257e77e..cf83b72dd3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -11,6 +11,7 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 # coverage!=4.4,>=4.0 # Apache-2.0 django-nose>=1.4.4 # BSD +flake8-import-order==0.12 # LGPLv3 mock>=2.0 # BSD mox3!=0.19.0,>=0.7.0 # Apache-2.0 nodeenv>=0.9.4 # BSD diff --git a/tox.ini b/tox.ini index b76cd74280..e202373587 100644 --- a/tox.ini +++ b/tox.ini @@ -123,6 +123,7 @@ ignore = # H904 Delay string interpolations at logging calls enable-extensions=H203,H904 max-complexity = 20 +import-order-style = pep8 [hacking] local-check-factory = horizon.hacking.checks.factory