Skip to content

Commit

Permalink
[flake8] Resolving F5?? errors (apache#3846)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored and michellethomas committed May 23, 2018
1 parent 29d1919 commit 2d9cc54
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 26 deletions.
4 changes: 3 additions & 1 deletion superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 14 additions & 6 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand All @@ -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}

Expand Down
5 changes: 4 additions & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
16 changes: 10 additions & 6 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br/>"
"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.<br/>"
"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"),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/celery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions tests/db_engine_specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_0_progress(self):
log = """
17/02/07 18:26:27 INFO log.PerfLogger: <PERFLOG method=compile from=org.apache.hadoop.hive.ql.Driver>
17/02/07 18:26:27 INFO log.PerfLogger: <PERFLOG method=parse from=org.apache.hadoop.hive.ql.Driver>
""".split('\n')
""".split('\n') # noqa ignore: E501
self.assertEquals(
0, HiveEngineSpec.progress(log))

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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))
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exclude =
superset/migrations
superset/templates
ignore =
E501
Q000
Q001
import-order-style = google
Expand Down

0 comments on commit 2d9cc54

Please sign in to comment.