From 2d9cc54889f6ba0179a899ff21e8167a6ad02506 Mon Sep 17 00:00:00 2001
From: John Bodley <4567245+john-bodley@users.noreply.github.com>
Date: Sun, 12 Nov 2017 11:09:22 -0800
Subject: [PATCH] [flake8] Resolving F5?? errors (#3846)
---
superset/config.py | 4 +++-
superset/models/core.py | 20 ++++++++++++++------
superset/sql_lab.py | 5 ++++-
superset/views/core.py | 16 ++++++++++------
tests/celery_tests.py | 3 ++-
tests/core_tests.py | 16 ++++++++++++----
tests/db_engine_specs_test.py | 12 ++++++------
tox.ini | 1 -
8 files changed, 51 insertions(+), 26 deletions(-)
diff --git a/superset/config.py b/superset/config.py
index 89b024c314789..95ee3b0dc1173 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -348,7 +348,9 @@ class CeleryConfig(object):
print('Loaded your LOCAL configuration at [{}]'.format(
os.environ[CONFIG_PATH_ENV_VAR]))
module = sys.modules[__name__]
- override_conf = imp.load_source('superset_config', os.environ[CONFIG_PATH_ENV_VAR])
+ override_conf = imp.load_source(
+ 'superset_config',
+ os.environ[CONFIG_PATH_ENV_VAR])
for key in dir(override_conf):
if key.isupper():
setattr(module, key, getattr(override_conf, key))
diff --git a/superset/models/core.py b/superset/models/core.py
index e067da4c2d115..130f63e0cbd02 100644
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -612,7 +612,10 @@ def get_effective_user(self, url, user_name=None):
effective_username = url.username
if user_name:
effective_username = user_name
- elif hasattr(g, 'user') and hasattr(g.user, 'username') and g.user.username is not None:
+ elif (
+ hasattr(g, 'user') and hasattr(g.user, 'username') and
+ g.user.username is not None
+ ):
effective_username = g.user.username
return effective_username
@@ -622,8 +625,12 @@ def get_sqla_engine(self, schema=None, nullpool=False, user_name=None):
url = self.db_engine_spec.adjust_database_uri(url, schema)
effective_username = self.get_effective_user(url, user_name)
# If using MySQL or Presto for example, will set url.username
- # If using Hive, will not do anything yet since that relies on a configuration parameter instead.
- self.db_engine_spec.modify_url_for_impersonation(url, self.impersonate_user, effective_username)
+ # If using Hive, will not do anything yet since that relies on a
+ # configuration parameter instead.
+ self.db_engine_spec.modify_url_for_impersonation(
+ url,
+ self.impersonate_user,
+ effective_username)
masked_url = self.get_password_masked_url(url)
logging.info("Database.get_sqla_engine(). Masked URL: {0}".format(masked_url))
@@ -635,9 +642,10 @@ def get_sqla_engine(self, schema=None, nullpool=False, user_name=None):
# If using Hive, this will set hive.server2.proxy.user=$effective_username
configuration = {}
configuration.update(
- self.db_engine_spec.get_configuration_for_impersonation(str(url),
- self.impersonate_user,
- effective_username))
+ self.db_engine_spec.get_configuration_for_impersonation(
+ str(url),
+ self.impersonate_user,
+ effective_username))
if configuration:
params["connect_args"] = {"configuration": configuration}
diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index 937f2222c6b2c..ab0f96009c756 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -176,7 +176,10 @@ def handle_error(msg):
conn = None
try:
engine = database.get_sqla_engine(
- schema=query.schema, nullpool=not ctask.request.called_directly, user_name=user_name)
+ schema=query.schema,
+ nullpool=not ctask.request.called_directly,
+ user_name=user_name,
+ )
conn = engine.raw_connection()
cursor = conn.cursor()
logging.info("Running query: \n{}".format(executed_sql))
diff --git a/superset/views/core.py b/superset/views/core.py
index 3cbe7a62ecc87..c106556edc99b 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -238,10 +238,11 @@ class DatabaseView(SupersetModelView, DeleteMixin): # noqa
"(http://docs.sqlalchemy.org/en/rel_1_0/core/metadata.html"
"#sqlalchemy.schema.MetaData) call. ", True),
'impersonate_user': _(
- "If Presto, all the queries in SQL Lab are going to be executed as the currently logged on user "
- "who must have permission to run them.
"
- "If Hive and hive.server2.enable.doAs is enabled, will run the queries as service account, "
- "but impersonate the currently logged on user via hive.server2.proxy.user property."),
+ "If Presto, all the queries in SQL Lab are going to be executed as the "
+ "currently logged on user who must have permission to run them.
"
+ "If Hive and hive.server2.enable.doAs is enabled, will run the queries as "
+ "service account, but impersonate the currently logged on user "
+ "via hive.server2.proxy.user property."),
}
label_columns = {
'expose_in_sqllab': _("Expose in SQL Lab"),
@@ -1102,7 +1103,9 @@ def explore(self, datasource_type, datasource_id):
action = request.args.get('action')
if action == 'overwrite' and not slice_overwrite_perm:
- return json_error_response("You don't have the rights to alter this slice", status=400)
+ return json_error_response(
+ "You don't have the rights to alter this slice",
+ status=400)
if action in ('saveas', 'overwrite'):
return self.save_or_overwrite_slice(
@@ -1462,7 +1465,8 @@ def testconn(self):
if database and uri:
url = make_url(uri)
- db_engine = models.Database.get_db_engine_spec_for_backend(url.get_backend_name())
+ db_engine = models.Database.get_db_engine_spec_for_backend(
+ url.get_backend_name())
db_engine.patch()
masked_url = database.get_password_masked_url_from_uri(uri)
diff --git a/tests/celery_tests.py b/tests/celery_tests.py
index a825b4d345f6f..b171b5259db7b 100644
--- a/tests/celery_tests.py
+++ b/tests/celery_tests.py
@@ -27,7 +27,8 @@
class CeleryConfig(object):
BROKER_URL = 'sqla+sqlite:///' + app.config.get('SQL_CELERY_DB_FILE_PATH')
CELERY_IMPORTS = ('superset.sql_lab', )
- CELERY_RESULT_BACKEND = 'db+sqlite:///' + app.config.get('SQL_CELERY_RESULTS_DB_FILE_PATH')
+ CELERY_RESULT_BACKEND = (
+ 'db+sqlite:///' + app.config.get('SQL_CELERY_RESULTS_DB_FILE_PATH'))
CELERY_ANNOTATIONS = {'sql_lab.add': {'rate_limit': '10/s'}}
CONCURRENCY = 1
diff --git a/tests/core_tests.py b/tests/core_tests.py
index 04f4746c6cf00..44da324a80208 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -283,7 +283,10 @@ def test_testconn(self, username='admin'):
'name': 'main',
'impersonate_user': False,
})
- response = self.client.post('/superset/testconn', data=data, content_type='application/json')
+ response = self.client.post(
+ '/superset/testconn',
+ data=data,
+ content_type='application/json')
assert response.status_code == 200
assert response.headers['Content-Type'] == 'application/json'
@@ -293,7 +296,10 @@ def test_testconn(self, username='admin'):
'name': 'main',
'impersonate_user': False,
})
- response = self.client.post('/superset/testconn', data=data, content_type='application/json')
+ response = self.client.post(
+ '/superset/testconn',
+ data=data,
+ content_type='application/json')
assert response.status_code == 200
assert response.headers['Content-Type'] == 'application/json'
@@ -311,7 +317,8 @@ def custom_password_store(uri):
assert conn.password != conn_pre.password
def test_databaseview_edit(self, username='admin'):
- # validate that sending a password-masked uri does not over-write the decrypted uri
+ # validate that sending a password-masked uri does not over-write the decrypted
+ # uri
self.login(username=username)
database = self.get_main_database(db.session)
sqlalchemy_uri_decrypted = database.sqlalchemy_uri_decrypted
@@ -740,7 +747,8 @@ def test_user_profile(self, username='admin'):
self.assertNotIn('message', data)
data = self.get_json_resp('/superset/fave_dashboards/{}/'.format(userid))
self.assertNotIn('message', data)
- data = self.get_json_resp('/superset/fave_dashboards_by_username/{}/'.format(username))
+ data = self.get_json_resp(
+ '/superset/fave_dashboards_by_username/{}/'.format(username))
self.assertNotIn('message', data)
def test_slice_id_is_always_logged_correctly_on_web_request(self):
diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py
index e348b90324a41..a2310d1d8098d 100644
--- a/tests/db_engine_specs_test.py
+++ b/tests/db_engine_specs_test.py
@@ -13,7 +13,7 @@ def test_0_progress(self):
log = """
17/02/07 18:26:27 INFO log.PerfLogger:
17/02/07 18:26:27 INFO log.PerfLogger:
- """.split('\n')
+ """.split('\n') # noqa ignore: E501
self.assertEquals(
0, HiveEngineSpec.progress(log))
@@ -35,7 +35,7 @@ def test_job_1_launched_stage_1_0_progress(self):
17/02/07 19:15:55 INFO ql.Driver: Total jobs = 2
17/02/07 19:15:55 INFO ql.Driver: Launching Job 1 out of 2
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
- """.split('\n')
+ """.split('\n') # noqa ignore: E501
self.assertEquals(0, HiveEngineSpec.progress(log))
def test_job_1_launched_stage_1_map_40_progress(self):
@@ -44,7 +44,7 @@ def test_job_1_launched_stage_1_map_40_progress(self):
17/02/07 19:15:55 INFO ql.Driver: Launching Job 1 out of 2
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 40%, reduce = 0%
- """.split('\n')
+ """.split('\n') # noqa ignore: E501
self.assertEquals(10, HiveEngineSpec.progress(log))
def test_job_1_launched_stage_1_map_80_reduce_40_progress(self):
@@ -54,7 +54,7 @@ def test_job_1_launched_stage_1_map_80_reduce_40_progress(self):
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 40%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 80%, reduce = 40%
- """.split('\n')
+ """.split('\n') # noqa ignore: E501
self.assertEquals(30, HiveEngineSpec.progress(log))
def test_job_1_launched_stage_2_stages_progress(self):
@@ -66,7 +66,7 @@ def test_job_1_launched_stage_2_stages_progress(self):
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 80%, reduce = 40%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-2 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 100%, reduce = 0%
- """.split('\n')
+ """.split('\n') # noqa ignore: E501
self.assertEquals(12, HiveEngineSpec.progress(log))
def test_job_2_launched_stage_2_stages_progress(self):
@@ -77,5 +77,5 @@ def test_job_2_launched_stage_2_stages_progress(self):
17/02/07 19:15:55 INFO ql.Driver: Launching Job 2 out of 2
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 0%, reduce = 0%
17/02/07 19:16:09 INFO exec.Task: 2017-02-07 19:16:09,173 Stage-1 map = 40%, reduce = 0%
- """.split('\n')
+ """.split('\n') # noqa ignore: E501
self.assertEquals(60, HiveEngineSpec.progress(log))
diff --git a/tox.ini b/tox.ini
index fc926b97e270f..177858dfe3971 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,7 +17,6 @@ exclude =
superset/migrations
superset/templates
ignore =
- E501
Q000
Q001
import-order-style = google