From f0f028ca35d9e3ea6a322ffc630985c83d22bb5b Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Wed, 11 Apr 2018 18:57:28 +0900 Subject: [PATCH] Fix E402 warnings E402 module level import not at top of file Change-Id: Ia8425ffe5b1325d00ae482d99b6764fd0fcbf822 --- doc/source/conf.py | 4 ++-- horizon/test/helpers.py | 5 +++-- openstack_dashboard/settings.py | 15 ++++++--------- openstack_dashboard/test/settings.py | 16 +++++++--------- tox.ini | 3 +-- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index d086700d3b..d3b84fd21f 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -30,6 +30,8 @@ import sys import django +import horizon.version + # NOTE(amotoki): Sphinx 1.6.x catches warnings from imported modules. # Ignore warnings from openstack_dashboard.settings in the doc build. # This can be dropped once Sphinx correctly ignore such warnings. @@ -45,8 +47,6 @@ sys.path.insert(0, ROOT) # This is required for ReadTheDocs.org, but isn't a bad idea anyway. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openstack_dashboard.settings') -import horizon.version - django.setup() diff --git a/horizon/test/helpers.py b/horizon/test/helpers.py index 27fd158a43..645ac278be 100644 --- a/horizon/test/helpers.py +++ b/horizon/test/helpers.py @@ -42,6 +42,9 @@ import six from django.contrib.staticfiles.testing \ import StaticLiveServerTestCase as LiveServerTestCase +from horizon import middleware + + LOG = logging.getLogger(__name__) @@ -68,8 +71,6 @@ try: except ImportError: pass -from horizon import middleware - # Makes output of failing mox tests much easier to read. wsgi.WSGIRequest.__repr__ = lambda self: "" diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index 0d9bedc1ed..a6c091db5d 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -25,13 +25,15 @@ import warnings from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ +from horizon.utils.escape import monkeypatch_escape + +from openstack_dashboard import enabled from openstack_dashboard import exceptions +from openstack_dashboard.local import enabled as local_enabled from openstack_dashboard import theme_settings from openstack_dashboard.utils import config from openstack_dashboard.utils import settings as settings_utils -from horizon.utils.escape import monkeypatch_escape - monkeypatch_escape() _LOG = logging.getLogger(__name__) @@ -461,16 +463,11 @@ if not SECRET_KEY: settings_utils.find_static_files(HORIZON_CONFIG, AVAILABLE_THEMES, THEME_COLLECTION_DIR, ROOT_PATH) - -# Load the pluggable dashboard settings -import openstack_dashboard.enabled -import openstack_dashboard.local.enabled - INSTALLED_APPS = list(INSTALLED_APPS) # Make sure it's mutable settings_utils.update_dashboards( [ - openstack_dashboard.enabled, - openstack_dashboard.local.enabled, + enabled, + local_enabled, ], HORIZON_CONFIG, INSTALLED_APPS, diff --git a/openstack_dashboard/test/settings.py b/openstack_dashboard/test/settings.py index 0253cced86..6202fd291f 100644 --- a/openstack_dashboard/test/settings.py +++ b/openstack_dashboard/test/settings.py @@ -16,18 +16,19 @@ import tempfile import six from django.utils.translation import pgettext_lazy -from horizon.test.settings import * # noqa: F403,H303 -from horizon.utils import secret_key -from openstack_dashboard import exceptions +from horizon.test.settings import * # noqa: F403,H303 from horizon.utils.escape import monkeypatch_escape +from horizon.utils import secret_key + +from openstack_dashboard import enabled +from openstack_dashboard import exceptions +from openstack_dashboard.utils import settings as settings_utils # this is used to protect from client XSS attacks, but it's worth # enabling in our test setup to find any issues it might cause monkeypatch_escape() -from openstack_dashboard.utils import settings as settings_utils - TEST_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_PATH = os.path.abspath(os.path.join(TEST_DIR, "..")) MEDIA_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'media')) @@ -116,13 +117,10 @@ STATICFILES_DIRS = settings_utils.get_xstatic_dirs( settings_utils.BASE_XSTATIC_MODULES, HORIZON_CONFIG ) -# Load the pluggable dashboard settings -import openstack_dashboard.enabled - INSTALLED_APPS = list(INSTALLED_APPS) # Make sure it's mutable settings_utils.update_dashboards( [ - openstack_dashboard.enabled, + enabled, ], HORIZON_CONFIG, INSTALLED_APPS, diff --git a/tox.ini b/tox.ini index 097aa71672..87c15adbb0 100644 --- a/tox.ini +++ b/tox.ini @@ -155,8 +155,7 @@ commands = [flake8] filename = *.py,django.wsgi exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/*,.ropeproject,node_modules,openstack_dashboard/enabled/* -# E402 module level import not at top of file -ignore = E402 +ignore = # Enable the following hacking rules which are disabled by default # H106 Do not put vim configuration in source files. # H203 Use assertIs(Not)None to check for None.