Nuria has uploaded a new change for review.
https://gerrit.wikimedia.org/r/121040
Change subject: Making code in master compliant with newer flake8 restrictions
......................................................................
Making code in master compliant with newer flake8 restrictions
Change-Id: Ia39a8c30a277126a34559323144151bf9a68077b
---
M tests/test_core_classes.py
M tests/test_models/test_aggregate_report.py
M tox.ini
M wikimetrics/configurables.py
M wikimetrics/controllers/authentication.py
M wikimetrics/controllers/forms/cohort_upload.py
M wikimetrics/metrics/bytes_added.py
M wikimetrics/metrics/metric.py
M wikimetrics/metrics/threshold.py
M wikimetrics/metrics/timeseries_metric.py
M wikimetrics/models/cohort.py
M wikimetrics/models/report_nodes/aggregate_report.py
M wikimetrics/models/validate_cohort.py
M wikimetrics/utils.py
14 files changed, 76 insertions(+), 74 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics
refs/changes/40/121040/1
diff --git a/tests/test_core_classes.py b/tests/test_core_classes.py
index 5c46935..dec787a 100644
--- a/tests/test_core_classes.py
+++ b/tests/test_core_classes.py
@@ -16,7 +16,7 @@
(host_one, projects) = get_host_projects(1)
assert_equals(host_one, 1)
assert_true('enwiki' in projects)
-
+
def test_get_host_projects_map(self):
project_host_map = get_host_projects_map()
assert_true('enwiki' in project_host_map)
@@ -36,11 +36,11 @@
#project_host_map_cache_file = 'project_host_map.json'
## make sure any cached file is deleted
#if os.path.exists(project_host_map_cache_file):
- #os.remove(project_host_map_cache_file)
-
+ #os.remove(project_host_map_cache_file)
+
#db.get_project_host_map(usecache=True)
#assert_true(os.path.exists(project_host_map_cache_file))
-
+
#os.remove(project_host_map_cache_file)
#db.get_project_host_map(usecache=False)
#assert_true(os.path.exists(project_host_map_cache_file))
diff --git a/tests/test_models/test_aggregate_report.py
b/tests/test_models/test_aggregate_report.py
index cfb8372..481be3b 100644
--- a/tests/test_models/test_aggregate_report.py
+++ b/tests/test_models/test_aggregate_report.py
@@ -299,31 +299,33 @@
{'date3': r(1.15), 'date4': r(1.7)}
)
-# NOTE: a sample output of AggregateReport:
-#{
- #'f5ca5afe-6b2d-4052-bd51-6cbeaeba5eb9': {
- #'Standard Deviation': {
- #'edits': 'Not Implemented'
- #},
- #'Individual Results': [
- #{
- #1: {'edits': 2},
- #2: {'edits': 3},
- #3: {'edits': 0},
- #None: {'edits': 0}
- #}
- #],
- #'Sum': {
- #'edits': Decimal('5')
- #},
- #'Average': {
- #'edits': Decimal('1.25')
- #}
- #},
- #'f5930c16-03ba-4069-a05e-e57f9f8e2f5c': {
- #1: {'edits': 2},
- #2: {'edits': 3},
- #3: {'edits': 0},
- #None: {'edits': 0}
- #}
-#}
+""""
+NOTE: a sample output of AggregateReport:
+{
+ 'f5ca5afe-6b2d-4052-bd51-6cbeaeba5eb9': {
+ 'Standard Deviation': {
+ 'edits': 'Not Implemented'
+ },
+ 'Individual Results': [
+ {
+ 1: {'edits': 2},
+ 2: {'edits': 3},
+ 3: {'edits': 0},
+ None: {'edits': 0}
+ }
+ ],
+ 'Sum': {
+ 'edits': Decimal('5')
+ },
+ 'Average': {
+ 'edits': Decimal('1.25')
+ }
+ },
+ 'f5930c16-03ba-4069-a05e-e57f9f8e2f5c': {
+ 1: {'edits': 2},
+ 2: {'edits': 3},
+ 3: {'edits': 0},
+ None: {'edits': 0}
+ }
+}
+"""
diff --git a/tox.ini b/tox.ini
index 98be08c..d335864 100644
--- a/tox.ini
+++ b/tox.ini
@@ -30,7 +30,8 @@
# E221: sometimes it makes more readable code if you can align a series of
statements
# E203: sometimes it makes more readable code if you can align a series of
statements
# E711: there are valid reasons to do column != None in SQL Alchemy
-ignore = W293,F401,E221,E203,E711
+# E265: block comment should start with '# '
+ignore = W293,F401,E221,E203,E711,E265
# line lengths should be limited but not to 80
max-line-length = 90
exclude = .venv,.tox,dist,doc,build,*.egg
diff --git a/wikimetrics/configurables.py b/wikimetrics/configurables.py
index ac99c4d..ca0e930 100644
--- a/wikimetrics/configurables.py
+++ b/wikimetrics/configurables.py
@@ -31,7 +31,7 @@
override_file = 'wikimetrics/config/test_config.yaml'
config_override = create_dict_from_text_config_file(override_file)
test_config = update_config_from_override(db_config, config_override)
-
+
test_config['PROJECT_HOST_NAMES'] = get_project_host_names_local()
return test_config
@@ -84,25 +84,25 @@
)
from werkzeug import url_decode, parse_options_header
import flask.ext.oauth as nasty_patch_to_oauth
-
+
global app
app = Flask('wikimetrics')
# TODO do we need this config to be created like an object instead of a
dictionary?
web_config = create_object_from_text_config_file(args.web_config)
- #if args.override_config:
- # override_config =
create_object_from_text_config_file(args.override_config)
- # TODO override one obj with other, can we use dict?
-
+ # if args.override_config:
+ # override_config =
create_object_from_text_config_file(args.override_config)
+ # TODO override one obj with other, can we use dict?
+
app.config.from_object(web_config)
-
+
version, latest = get_wikimetrics_version()
app.config['WIKIMETRICS_LATEST'] = latest
app.config['WIKIMETRICS_VERSION'] = version
-
+
global login_manager
login_manager = LoginManager()
login_manager.init_app(app)
-
+
global google
oauth = OAuth()
google = oauth.remote_app(
@@ -123,7 +123,7 @@
consumer_key=app.config['GOOGLE_CLIENT_ID'],
consumer_secret=app.config['GOOGLE_CLIENT_SECRET'],
)
-
+
def better_parse_response(resp, content, strict=False):
ct, options = parse_options_header(resp['content-type'])
if ct in ('application/json', 'text/javascript'):
@@ -146,10 +146,10 @@
return content
charset = options.get('charset', 'utf-8')
return url_decode(content, charset=charset).to_dict()
-
+
# TODO: Even worse, definitely patch upstream or consider switching to
rauth
nasty_patch_to_oauth.parse_response = better_parse_response
-
+
# TODO: patch upstream
# NOTE: a million thanks to Merlijn_van_Deen, author of
#
https://wikitech.wikimedia.org/wiki/Setting_up_Flask_cgi_app_as_a_tool/OAuth
@@ -176,7 +176,7 @@
data=data
)
return data
-
+
global meta_mw
meta_mw_base_url = app.config['META_MW_BASE_URL']
meta_mw = MediaWikiOAuthRemoteApp(
@@ -204,15 +204,15 @@
to get a user,password, host and dbName
"""
from .database import Database
-
+
db_config = create_dict_from_text_config_file(args.db_config)
config_override = {}
if args.override_config:
config_override =
create_dict_from_text_config_file(args.override_config)
db_config = update_config_from_override(db_config, config_override)
-
+
global db
-
+
user, password, host, db_name = parse_db_connection_string(
db_config['WIKIMETRICS_ENGINE_URL'])
db_config['WIKIMETRICS'] = {
@@ -221,16 +221,16 @@
'HOST': host,
'DBNAME': db_name,
}
-
+
if db_config.get('DEBUG'):
db_config['PROJECT_HOST_NAMES'] = get_project_host_names_local()
-
+
db = Database(db_config)
def config_queue(args):
from celery import Celery
-
+
# create and configure celery app
global queue
queue = Celery('wikimetrics', include=['wikimetrics'])
diff --git a/wikimetrics/controllers/authentication.py
b/wikimetrics/controllers/authentication.py
index 9a67735..d2991cb 100644
--- a/wikimetrics/controllers/authentication.py
+++ b/wikimetrics/controllers/authentication.py
@@ -43,7 +43,7 @@
return json_error('Please Login to access {0}'.format(request.path))
if (
- request.endpoint
+ request.endpoint
and not request.path.startswith('/static/')
and not request.path == 'favicon.ico'
and not getattr(app.view_functions[request.endpoint], 'is_public',
False)
diff --git a/wikimetrics/controllers/forms/cohort_upload.py
b/wikimetrics/controllers/forms/cohort_upload.py
index 6ec6efb..bc0e471 100644
--- a/wikimetrics/controllers/forms/cohort_upload.py
+++ b/wikimetrics/controllers/forms/cohort_upload.py
@@ -65,7 +65,7 @@
"""
records = []
for r in unparsed:
- if not r is None and len(r) > 0:
+ if r is not None and len(r) > 0:
# NOTE: the reason for the crazy -1 and comma joins
# is that some users can have commas in their name
# NOTE: This makes it impossible to add fields to the csv in the
future,
diff --git a/wikimetrics/metrics/bytes_added.py
b/wikimetrics/metrics/bytes_added.py
index ea7efed..accd2d4 100644
--- a/wikimetrics/metrics/bytes_added.py
+++ b/wikimetrics/metrics/bytes_added.py
@@ -107,8 +107,7 @@
.join(Page)\
.outerjoin(
PreviousRevision,
- Revision.rev_parent_id == PreviousRevision.c.rev_id
- )\
+ Revision.rev_parent_id == PreviousRevision.c.rev_id)\
.filter(Page.page_namespace.in_(self.namespaces.data))\
.filter(Revision.rev_user.in_(user_ids))\
.filter(Revision.rev_timestamp > start_date)\
diff --git a/wikimetrics/metrics/metric.py b/wikimetrics/metrics/metric.py
index f3a9648..f5dcaa0 100644
--- a/wikimetrics/metrics/metric.py
+++ b/wikimetrics/metrics/metric.py
@@ -14,8 +14,10 @@
show_in_ui = False
id = None # unique identifier for client-side use
- label = None # this will be displayed as the title of the
metric-specific
- # tab in the request form
+
+ # this will be displayed as the title of the metric-specific
+ # tab in the request form
+ label = None
description = None # basic description of what the metric does
def __call__(self, user_ids, session):
diff --git a/wikimetrics/metrics/threshold.py b/wikimetrics/metrics/threshold.py
index ba20def..caca2c7 100644
--- a/wikimetrics/metrics/threshold.py
+++ b/wikimetrics/metrics/threshold.py
@@ -150,9 +150,7 @@
o_r,
and_(
MediawikiUser.user_id == o_r.c.rev_user,
- o_r.c.number == number_of_edits
- )
- ) \
+ o_r.c.number == number_of_edits)) \
.filter(MediawikiUser.user_id.in_(user_ids))
return {
diff --git a/wikimetrics/metrics/timeseries_metric.py
b/wikimetrics/metrics/timeseries_metric.py
index 8206ecf..f271a71 100644
--- a/wikimetrics/metrics/timeseries_metric.py
+++ b/wikimetrics/metrics/timeseries_metric.py
@@ -147,7 +147,7 @@
# get results by user and by date
for row in query_results:
user_id = row[0]
- if not user_id in results:
+ if user_id not in results:
results[user_id] = OrderedDict()
date_slice = None
@@ -156,7 +156,7 @@
for label, index, default in submetrics:
if date_slice:
- if not label in results[user_id]:
+ if label not in results[user_id]:
results[user_id][label] = dict()
results[user_id][label][date_slice] = row[index]
else:
@@ -196,7 +196,7 @@
for user_id, user_submetrics in results_by_user.iteritems():
for label, i, default in submetrics:
- if not label or not user_submetrics or not label in
user_submetrics:
+ if not label or not user_submetrics or label not in
user_submetrics:
continue
defaults = timeseries_slices.copy()
defaults.update(user_submetrics[label])
diff --git a/wikimetrics/models/cohort.py b/wikimetrics/models/cohort.py
index 98f6ad5..bb73391 100644
--- a/wikimetrics/models/cohort.py
+++ b/wikimetrics/models/cohort.py
@@ -127,9 +127,9 @@
.filter(User.id == user_id)\
.filter(Cohort.enabled)
- if not by_id is None:
+ if by_id is not None:
query = query.filter(Cohort.id == by_id)
- if not by_name is None:
+ if by_name is not None:
query = query.filter(Cohort.name == by_name)
cohort, role = query.one()
diff --git a/wikimetrics/models/report_nodes/aggregate_report.py
b/wikimetrics/models/report_nodes/aggregate_report.py
index dd92c66..64c3fcf 100644
--- a/wikimetrics/models/report_nodes/aggregate_report.py
+++ b/wikimetrics/models/report_nodes/aggregate_report.py
@@ -83,7 +83,7 @@
Aggregation.AVG
)
if self.aggregate_std_deviation:
- if not Aggregation.AVG in aggregated_results:
+ if Aggregation.AVG not in aggregated_results:
average = self.calculate(child_results, Aggregation.AVG)
else:
average = aggregated_results[Aggregation.AVG]
@@ -125,17 +125,17 @@
continue
value = results_by_user[user_id][key]
- value_is_not_censored = not CENSORED in
results_by_user[user_id]\
+ value_is_not_censored = CENSORED not in
results_by_user[user_id]\
or results_by_user[user_id][CENSORED] != 1
# handle timeseries aggregation
if isinstance(value, dict):
- if not key in aggregation:
+ if key not in aggregation:
aggregation[key] = OrderedDict()
helper[key] = dict()
for subkey in value:
- if not subkey in aggregation[key]:
+ if subkey not in aggregation[key]:
aggregation[key][subkey] = 0
helper[key][subkey] = dict()
helper[key][subkey]['sum'] = Decimal(0.0)
@@ -166,14 +166,14 @@
# handle normal aggregation
else:
- if not key in aggregation:
+ if key not in aggregation:
aggregation[key] = 0
helper[key] = dict()
helper[key]['sum'] = Decimal(0.0)
helper[key]['square_diffs'] = Decimal(0.0)
helper[key]['count'] = 0
- if value_is_not_censored and not value is None:
+ if value_is_not_censored and value is not None:
helper[key]['sum'] += Decimal(value)
helper[key]['count'] += 1
if type_of_aggregate == Aggregation.STD:
diff --git a/wikimetrics/models/validate_cohort.py
b/wikimetrics/models/validate_cohort.py
index 0bd3c0f..86dbe56 100644
--- a/wikimetrics/models/validate_cohort.py
+++ b/wikimetrics/models/validate_cohort.py
@@ -155,7 +155,7 @@
continue
wu.project = normalized_project
- if not wu.project in wikiusers_by_project:
+ if wu.project not in wikiusers_by_project:
wikiusers_by_project[wu.project] = []
wikiusers_by_project[wu.project].append(wu)
diff --git a/wikimetrics/utils.py b/wikimetrics/utils.py
index 9cadd5d..166d78b 100644
--- a/wikimetrics/utils.py
+++ b/wikimetrics/utils.py
@@ -112,7 +112,7 @@
uniques = dict()
for o in list_of_objects:
key = key_function(o)
- if not key in uniques:
+ if key not in uniques:
uniques[key] = o
return uniques.values()
--
To view, visit https://gerrit.wikimedia.org/r/121040
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia39a8c30a277126a34559323144151bf9a68077b
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Nuria <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits