Fix E402 warnings

E402 module level import not at top of file

Change-Id: Ia8425ffe5b1325d00ae482d99b6764fd0fcbf822
This commit is contained in:
Akihiro Motoki 2018-04-11 18:57:28 +09:00
parent 11eb4e9d3e
commit f0f028ca35
5 changed files with 19 additions and 24 deletions

View File

@ -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()

View File

@ -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: "<class 'django.http.HttpRequest'>"

View File

@ -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,

View File

@ -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,

View File

@ -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.