[LNT] r307721 - lnt/server/db: Fix pep8 warnings
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 11 15:13:17 PDT 2017
Author: matze
Date: Tue Jul 11 15:13:17 2017
New Revision: 307721
URL: http://llvm.org/viewvc/llvm-project?rev=307721&view=rev
Log:
lnt/server/db: Fix pep8 warnings
Modified:
lnt/trunk/lnt/server/db/fieldchange.py
lnt/trunk/lnt/server/db/migrate.py
lnt/trunk/lnt/server/db/regression.py
lnt/trunk/lnt/server/db/rules_manager.py
lnt/trunk/lnt/server/db/search.py
lnt/trunk/lnt/server/db/testsuite.py
lnt/trunk/lnt/server/db/testsuitedb.py
lnt/trunk/lnt/server/db/util.py
lnt/trunk/lnt/server/db/v4db.py
Modified: lnt/trunk/lnt/server/db/fieldchange.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/fieldchange.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/fieldchange.py (original)
+++ lnt/trunk/lnt/server/db/fieldchange.py Tue Jul 11 15:13:17 2017
@@ -33,10 +33,10 @@ def delete_fieldchange(ts, change):
# Remove the idicators that point to this change.
for ind in indicators:
ts.delete(ind)
-
+
# Now we can remove the change, itself.
ts.delete(change)
-
+
# We might have just created a regression with no changes.
# If so, delete it as well.
deleted_ids = []
@@ -134,7 +134,7 @@ def regenerate_fieldchanges_for_run(ts,
# This can happen from time to time.
# So, lets retry once.
found, new_reg = identify_related_changes(ts, f)
-
+
if found:
logger.info("Found field change: {}".format(
run.machine))
@@ -201,7 +201,8 @@ def identify_related_changes(ts, fc):
confidence += percent_similar(regression_change.machine.name,
fc.machine.name)
- confidence += percent_similar(regression_change.test.name, fc.test.name)
+ confidence += percent_similar(regression_change.test.name,
+ fc.test.name)
if regression_change.field == fc.field:
confidence += 1.0
Modified: lnt/trunk/lnt/server/db/migrate.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/migrate.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/migrate.py (original)
+++ lnt/trunk/lnt/server/db/migrate.py Tue Jul 11 15:13:17 2017
@@ -23,6 +23,7 @@ import lnt.server.db.util
Base = sqlalchemy.ext.declarative.declarative_base()
+
class SchemaVersion(Base):
__tablename__ = 'SchemaVersion'
@@ -39,6 +40,7 @@ class SchemaVersion(Base):
###
# Migrations auto-discovery.
+
def _load_migrations():
"""
Load available migration scripts from a directory.
@@ -77,7 +79,7 @@ def _load_migrations():
continue
# Check the version numbers for validity.
- version,next_version = map(int, m.groups())
+ version, next_version = map(int, m.groups())
if next_version != version + 1:
logger.error(
"invalid script name %r in schema migration directory: %r",
@@ -112,6 +114,7 @@ def _load_migrations():
###
# Auto-upgrading support.
+
def _set_schema_version(engine, schema_name, new_version):
# Keep the updating to a single transaction that is immediately committed.
session = sqlalchemy.orm.sessionmaker(engine)()
@@ -176,6 +179,7 @@ def update_schema(engine, versions, avai
return True
+
def update(engine):
any_changed = False
@@ -221,8 +225,9 @@ def update(engine):
if any_changed:
logger.info("database auto-upgraded")
+
def update_path(path):
- # If the path includes no database type, assume sqlite.
+ # If the path includes no database type, assume sqlite.
if lnt.server.db.util.path_has_no_database_type(path):
path = 'sqlite:///' + path
Modified: lnt/trunk/lnt/server/db/regression.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/regression.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/regression.py (original)
+++ lnt/trunk/lnt/server/db/regression.py Tue Jul 11 15:13:17 2017
@@ -68,7 +68,6 @@ def rebuild_title(ts, regression):
title = (title[:120] + '...') if len(title) > 120 else title
regression.title = title
return regression
-
def get_all_orders_for_machine(ts, machine):
@@ -107,7 +106,7 @@ def get_current_runs_of_fieldchange(ts,
before_runs = get_runs_for_order_and_machine(ts, fc.start_order_id,
fc.machine_id)
newest_order = get_all_orders_for_machine(ts, fc.machine_id)[-1]
-
+
after_runs = get_runs_for_order_and_machine(ts, newest_order.id,
fc.machine_id)
return ChangeRuns(before_runs, after_runs)
@@ -122,7 +121,7 @@ def get_first_runs_of_fieldchange(ts, fc
def get_cr_for_field_change(ts, field_change, current=False):
- """Given a filed_change, calculate a comparison result for that change.
+ """Given a filed_change, calculate a comparison result for that change.
And the last run."""
if current:
runs = get_current_runs_of_fieldchange(ts, field_change)
@@ -130,7 +129,8 @@ def get_cr_for_field_change(ts, field_ch
runs = get_runs_of_fieldchange(ts, field_change)
runs_all = list(runs.before)
runs_all.extend(runs.after)
- ri = RunInfo(ts, [r.id for r in runs_all], only_tests=[field_change.test_id])
+ ri = RunInfo(ts, [r.id for r in runs_all],
+ only_tests=[field_change.test_id])
cr = ri.get_comparison_result(runs.after, runs.before,
field_change.test.id, field_change.field,
ts.Sample.get_hash_of_binary_field())
Modified: lnt/trunk/lnt/server/db/rules_manager.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/rules_manager.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/rules_manager.py (original)
+++ lnt/trunk/lnt/server/db/rules_manager.py Tue Jul 11 15:13:17 2017
@@ -1,12 +1,12 @@
"""
Define facilities for automatically applying rules to data.
"""
-
import os
import re
from lnt.util import logger
from lnt.testing.util.commands import timed
+
def load_rules():
"""
Load available rules scripts from a directory.
@@ -22,8 +22,7 @@ def load_rules():
r'^rule_(.*)\.py$')
rule_scripts = {}
- rules_path = os.path.join(os.path.dirname(__file__),
- 'rules')
+ rules_path = os.path.join(os.path.dirname(__file__), 'rules')
for item in os.listdir(rules_path):
# Ignore certain known non-scripts.
if item in ('README.txt', '__init__.py') or item.endswith('.pyc'):
@@ -40,16 +39,18 @@ def load_rules():
# Allow rules to be disabled by name
if name.endswith("disabled"):
continue
-
+
rule_scripts[name] = os.path.join(rules_path, item)
return rule_scripts
# Places our rules can hook to.
-HOOKS = {'post_test_hook':[],
- 'post_submission_hook':[],
- 'post_regression_create_hook':[],
- 'is_useful_change': []}
+HOOKS = {
+ 'post_test_hook': [],
+ 'post_submission_hook': [],
+ 'post_regression_create_hook': [],
+ 'is_useful_change': [],
+}
DESCRIPTIONS = {}
@@ -66,11 +67,13 @@ def register_hooks():
HOOKS[hook_name].append(globals[hook_name])
return HOOKS
+
def post_submission_hooks(ts, run_id):
"""Run all the post submission hooks on the submitted run."""
for func in HOOKS['post_submission_hook']:
func(ts, run_id)
+
def is_useful_change(ts, field_change):
"""Run all the change filters. If any are false, drop this change."""
all_filters = []
Modified: lnt/trunk/lnt/server/db/search.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/search.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/search.py (original)
+++ lnt/trunk/lnt/server/db/search.py Tue Jul 11 15:13:17 2017
@@ -1,21 +1,22 @@
import re
+
def _naive_search_for_run(ts, query, num_results, default_machine):
"""
This 'naive' search doesn't rely on any indexes so can be used without
full-text search enabled. This does make it less clever however.
- It is able to match queries for machine names and order numbers (specifically
- llvm_project_revision numbers). The revision numbers may be partial and may be
- preceded by '#' or 'r'. Any other non-integer tokens are considered to be partial
- matches for a machine name; any machine that contains ALL of the tokens will be
- searched.
+ It is able to match queries for machine names and order numbers
+ (specifically llvm_project_revision numbers). The revision numbers may be
+ partial and may be preceded by '#' or 'r'. Any other non-integer tokens are
+ considered to be partial matches for a machine name; any machine that
+ contains ALL of the tokens will be searched.
"""
order_re = re.compile(r'[r#]?(\d+)')
machine_queries = []
order_queries = []
-
+
# First, tokenize the query string.
for q in query.split(' '):
if not q:
@@ -28,8 +29,8 @@ def _naive_search_for_run(ts, query, num
machine_queries.append(q)
if not machine_queries and not default_machine:
- # No machines to query: no matches. We can't query all machines, we'd end up
- # doing a full table scan and that is not scalable.
+ # No machines to query: no matches. We can't query all machines, we'd
+ # end up doing a full table scan and that is not scalable.
return []
machines = []
@@ -46,28 +47,32 @@ def _naive_search_for_run(ts, query, num
llvm_project_revision_idx = [i
for i, f in enumerate(ts.Order.fields)
if f.name == 'llvm_project_revision'][0]
- llvm_project_revision_col = ts.Order.fields[llvm_project_revision_idx].column
-
+ llvm_project_revision_col = \
+ ts.Order.fields[llvm_project_revision_idx].column
+
q = ts.query(ts.Run) \
.filter(ts.Run.machine_id.in_(machines)) \
.filter(ts.Run.order_id == ts.Order.id) \
- .filter(llvm_project_revision_col != None)
+ .filter(llvm_project_revision_col.isnot(None))
if order_queries:
oq = '%' + str(order_queries[0]) + '%'
q = q.filter(llvm_project_revision_col.like(oq))
return q.order_by(ts.Run.id.desc()).limit(num_results).all()
-
+
+
def search(ts, query,
num_results=8, default_machine=None):
"""
- Performs a textual search for a run. The exact syntax supported depends on the engine
- used to perform the search; see _naive_search_for_run for the minimum supported syntax.
+ Performs a textual search for a run. The exact syntax supported depends on
+ the engine used to perform the search; see _naive_search_for_run for the
+ minimum supported syntax.
ts: TestSuite object
query: Textual query string
num_results: Number of results to return
- default_machine: If no machines were specified (only orders), return results from this machine.
+ default_machine: If no machines were specified (only orders), return
+ results from this machine.
Returns a list of Run objects.
"""
Modified: lnt/trunk/lnt/server/db/testsuite.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuite.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuite.py (original)
+++ lnt/trunk/lnt/server/db/testsuite.py Tue Jul 11 15:13:17 2017
@@ -98,7 +98,8 @@ class TestSuiteJSONSchema(Base):
type = metric_desc['type']
if old_metric is not None:
if old_metric['type'] != type:
- raise _MigrationError("Type mismatch in metric '%s'" % name)
+ raise _MigrationError("Type mismatch in metric '%s'" %
+ name)
elif not dry_run:
# Add missing columns
column = testsuitedb.make_sample_column(name, type)
@@ -139,7 +140,6 @@ class TestSuiteJSONSchema(Base):
raise _MigrationError("Order fields removed: %s" %
", ".join(old_order_fields.keys()))
-
old_machine_fields = {}
for field_desc in old.get('machine_fields', []):
name = field_desc['name']
@@ -157,7 +157,7 @@ class TestSuiteJSONSchema(Base):
if len(old_machine_fields) > 0:
raise _MigrationError("Machine fields removed: %s" %
", ".join(old_machine_fields.keys()))
- # The rest should just be metadata that we can upgrade
+ # The rest should just be metadata that we can upgrade
return True
@@ -241,7 +241,7 @@ class TestSuite(Base):
bigger_is_better_int = 1 if bigger_is_better else 0
field = SampleField(name, metric_type, info_key=None,
- status_field = None,
+ status_field=None,
bigger_is_better=bigger_is_better_int)
sample_fields.append(field)
ts.sample_fields = sample_fields
@@ -252,8 +252,8 @@ class TestSuite(Base):
name = self.name
schema = TestSuiteJSONSchema(name, self.jsonschema)
prev_schema = v4db.query(TestSuiteJSONSchema) \
- .filter(TestSuiteJSONSchema.testsuite_name == name) \
- .first()
+ .filter(TestSuiteJSONSchema.testsuite_name == name) \
+ .first()
if prev_schema is not None:
if prev_schema.jsonschema != schema.jsonschema:
logger.info("Previous Schema:")
Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Tue Jul 11 15:13:17 2017
@@ -584,7 +584,7 @@ class TestSuiteDB(object):
return '{}_{}:"{}"'.format(db_key_name,
self.__class__.__name__,
"<Deleted>")
-
+
def __json__(self):
return strip(self.__dict__)
Modified: lnt/trunk/lnt/server/db/util.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/util.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/util.py (original)
+++ lnt/trunk/lnt/server/db/util.py Tue Jul 11 15:13:17 2017
@@ -4,6 +4,7 @@ import re
PATH_DATABASE_TYPE_RE = re.compile('\w+\:\/\/')
+
def path_has_no_database_type(path):
return PATH_DATABASE_TYPE_RE.match(path) is None
Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=307721&r1=307720&r2=307721&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Tue Jul 11 15:13:17 2017
@@ -44,7 +44,7 @@ class V4DB(object):
name = suite.name
self._extra_suites[name] = suite
- def get(self, name, default = None):
+ def get(self, name, default=None):
# Check the test suite cache, to avoid gratuitous reinstantiation.
#
# FIXME: Invalidation?
@@ -63,7 +63,8 @@ class V4DB(object):
if ts is None:
return default
- # Instantiate the per-test suite wrapper object for this test suite.
+ # Instantiate the per-test suite wrapper object for this test
+ # suite.
self._cache[name] = ts = lnt.server.db.testsuitedb.TestSuiteDB(
self.v4db, name, ts, create_tables=create_tables)
return ts
@@ -73,7 +74,7 @@ class V4DB(object):
if ts is None:
raise IndexError(name)
return ts
-
+
def keys(self):
return iter(self)
@@ -83,7 +84,7 @@ class V4DB(object):
def items(self):
for name in self:
- yield name,self[name]
+ yield name, self[name]
def _load_schema_file(self, schema_file):
with open(schema_file) as schema_fd:
@@ -150,7 +151,9 @@ class V4DB(object):
except KeyError:
fatal("status kinds not initialized!")
- sample_types = {st.name: st for st in self.query(testsuite.SampleType).all()}
+ sample_types = {
+ st.name: st for st in self.query(testsuite.SampleType).all()
+ }
# Resolve or create the known sample types.
try:
self.real_sample_type = sample_types["Real"]
@@ -164,8 +167,8 @@ class V4DB(object):
def close(self):
if self.session is not None:
self.session.close()
-
- @staticmethod
+
+ @staticmethod
def close_engine(db_path):
"""Rip down everything about this path, so we can make it
new again. This is used for tests that need to make a fresh
@@ -173,7 +176,7 @@ class V4DB(object):
V4DB._engine[db_path].dispose()
V4DB._engine.pop(db_path)
V4DB._db_updated.remove(db_path)
-
+
@staticmethod
def close_all_engines():
for key in V4DB._engine.keys():
@@ -189,8 +192,8 @@ class V4DB(object):
@property
def testsuite(self):
# This is the start of "magic" part of V4DB, which allows us to get
- # fully bound SA instances for databases which are effectively described
- # by the TestSuites table.
+ # fully bound SA instances for databases which are effectively
+ # described by the TestSuites table.
# The magic starts by returning a object which will allow us to use
# dictionary like access to get the per-test suite database wrapper.
More information about the llvm-commits
mailing list