[LNT] r372551 - [LNT] Python 3 support: Use absolute import by default
Thomas Preud'homme via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 00:43:27 PDT 2019
Author: thopre
Date: Mon Sep 23 00:43:27 2019
New Revision: 372551
URL: http://llvm.org/viewvc/llvm-project?rev=372551&view=rev
Log:
[LNT] Python 3 support: Use absolute import by default
Forces module import to be absolute by default on Python 2 since this is
the default for Python 3. Adapts relative imports to use the relative
import symtax 'from . import foo' or 'from .pkg import foo'.
Also remove unnecessary circular import dependency between testsuite and
testsuitedb by moving functions used by testsuite but currently in
testsuitedb into module testsuite. Finally adds type hints into
lnt.formats to avoid warnings from mypy due to change to relative import
syntax.
Changes to adapt syntax of relative import was produced by running
futurize's stage1 libfuturize.fixes.fix_absolute_import, while breaking
of circular dependency was done manually.
Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls
Reviewed By: hubert.reinterpretcast
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D67811
Modified:
lnt/trunk/lnt/formats/__init__.py
lnt/trunk/lnt/server/db/testsuite.py
lnt/trunk/lnt/server/db/testsuitedb.py
lnt/trunk/lnt/tests/nt.py
Modified: lnt/trunk/lnt/formats/__init__.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/formats/__init__.py?rev=372551&r1=372550&r2=372551&view=diff
==============================================================================
--- lnt/trunk/lnt/formats/__init__.py (original)
+++ lnt/trunk/lnt/formats/__init__.py Mon Sep 23 00:43:27 2019
@@ -8,12 +8,13 @@ callable taking a Python object to write
"""
from __future__ import absolute_import
+from typing import List, Dict
from .PlistFormat import format as plist
from .JSONFormat import format as json
-formats = [plist, json]
-formats_by_name = dict((f['name'], f) for f in formats)
-format_names = list(formats_by_name.keys())
+formats = [plist, json] # type: List[Dict]
+formats_by_name = dict((f['name'], f) for f in formats) # type: Dict[str, Dict]
+format_names = list(formats_by_name.keys()) # type: List[str]
def get_format(name):
Modified: lnt/trunk/lnt/server/db/testsuite.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuite.py?rev=372551&r1=372550&r2=372551&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuite.py (original)
+++ lnt/trunk/lnt/server/db/testsuite.py Mon Sep 23 00:43:27 2019
@@ -10,7 +10,7 @@ from . import util
import sqlalchemy
import sqlalchemy.ext.declarative
import sqlalchemy.orm
-from sqlalchemy import Column, Integer, ForeignKey, String, Binary
+from sqlalchemy import Column, Integer, ForeignKey, String, Binary, Float
from sqlalchemy.orm import relation
from lnt.util import logger
@@ -59,6 +59,35 @@ class StatusKind(Base):
return '%s%r' % (self.__class__.__name__, (self.name,))
+_sample_type_to_sql = {
+ 'Real': Float,
+ 'Hash': String,
+ 'Status': Integer,
+}
+
+
+def is_known_sample_type(name):
+ return name in _sample_type_to_sql
+
+
+def make_sample_column(name, type):
+ sqltype = _sample_type_to_sql.get(type)
+ if sqltype is None:
+ raise ValueError("test suite defines unknown sample type %r" % type)
+ options = []
+ if type == 'Status':
+ options.append(ForeignKey(StatusKind.id))
+ return Column(name, sqltype, *options)
+
+
+def make_run_column(name):
+ return Column(name, String(256))
+
+
+def make_machine_column(name):
+ return Column(name, String(256))
+
+
class _MigrationError(Exception):
def __init__(self, message):
full_message = \
@@ -114,7 +143,6 @@ class TestSuite(Base):
@staticmethod
def from_json(data):
- from . import testsuitedb
if data.get('format_version') != '2':
raise ValueError("Expected \"format_version\": \"2\" in schema")
name = data['name']
@@ -150,7 +178,7 @@ class TestSuite(Base):
display_name = metric_desc.get('display_name')
unit = metric_desc.get('unit')
unit_abbrev = metric_desc.get('unit_abbrev')
- if not testsuitedb.is_known_sample_type(metric_type_name):
+ if not is_known_sample_type(metric_type_name):
raise ValueError("Unknown metric type '%s'" %
metric_type_name)
metric_type = SampleType(metric_type_name)
@@ -350,7 +378,6 @@ class SampleField(FieldMixin, Base):
def _upgrade_to(connectable, tsschema, new_schema, dry_run=False):
- from . import testsuitedb
new = json.loads(new_schema.jsonschema)
old = json.loads(tsschema.jsonschema)
ts_name = new['name']
@@ -371,7 +398,7 @@ def _upgrade_to(connectable, tsschema, n
name)
elif not dry_run:
# Add missing columns
- column = testsuitedb.make_sample_column(name, type)
+ column = make_sample_column(name, type)
util.add_column(connectable, '%s_Sample' % ts_name, column)
if len(old_metrics) != 0:
@@ -398,7 +425,7 @@ def _upgrade_to(connectable, tsschema, n
old_field = old_run_fields.pop(name, None)
# Add missing columns
if old_field is None and not dry_run:
- column = testsuitedb.make_run_column(name)
+ column = make_run_column(name)
util.add_column(connectable, '%s_Run' % ts_name, column)
if len(old_run_fields) > 0:
@@ -418,7 +445,7 @@ def _upgrade_to(connectable, tsschema, n
old_field = old_machine_fields.pop(name, None)
# Add missing columns
if old_field is None and not dry_run:
- column = testsuitedb.make_machine_column(name)
+ column = make_machine_column(name)
util.add_column(connectable, '%s_Machine' % ts_name, column)
if len(old_machine_fields) > 0:
Modified: lnt/trunk/lnt/server/db/testsuitedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/testsuitedb.py?rev=372551&r1=372550&r2=372551&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/testsuitedb.py (original)
+++ lnt/trunk/lnt/server/db/testsuitedb.py Mon Sep 23 00:43:27 2019
@@ -33,35 +33,6 @@ def _dict_update_abort_on_duplicates(bas
base_dict[key] = value
-_sample_type_to_sql = {
- 'Real': Float,
- 'Hash': String,
- 'Status': Integer,
-}
-
-
-def is_known_sample_type(name):
- return name in _sample_type_to_sql
-
-
-def make_sample_column(name, type):
- sqltype = _sample_type_to_sql.get(type)
- if sqltype is None:
- raise ValueError("test suite defines unknown sample type %r" % type)
- options = []
- if type == 'Status':
- options.append(ForeignKey(testsuite.StatusKind.id))
- return Column(name, sqltype, *options)
-
-
-def make_run_column(name):
- return Column(name, String(256))
-
-
-def make_machine_column(name):
- return Column(name, String(256))
-
-
class MachineInfoChanged(ValueError):
pass
@@ -153,7 +124,8 @@ class TestSuiteDB(object):
raise ValueError("test suite defines reserved key %r" % (
iname))
- class_dict[iname] = item.column = make_machine_column(iname)
+ item.column = testsuite.make_machine_column(iname)
+ class_dict[iname] = item.column
def __init__(self, name_value):
self.id = None
@@ -356,7 +328,8 @@ class TestSuiteDB(object):
raise ValueError("test suite defines reserved key %r" %
(iname,))
- class_dict[iname] = item.column = make_run_column(iname)
+ item.column = testsuite.make_run_column(iname)
+ class_dict[iname] = item.column
def __init__(self, new_id, machine, order, start_time, end_time):
self.id = new_id
@@ -537,7 +510,8 @@ class TestSuiteDB(object):
raise ValueError("test suite defines reserved key %r" %
(iname,))
- item.column = make_sample_column(iname, item.type.name)
+ item.column = testsuite.make_sample_column(iname,
+ item.type.name)
class_dict[iname] = item.column
def __init__(self, run, test, **kwargs):
Modified: lnt/trunk/lnt/tests/nt.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/nt.py?rev=372551&r1=372550&r2=372551&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/nt.py (original)
+++ lnt/trunk/lnt/tests/nt.py Mon Sep 23 00:43:27 2019
@@ -1,4 +1,5 @@
"""LLVM test-suite compile and execution tests"""
+from __future__ import absolute_import
from __future__ import print_function
import csv
import os
@@ -33,7 +34,7 @@ from lnt.server.reporting.analysis impor
from lnt.server.reporting.analysis import REGRESSED, IMPROVED
from lnt.util import logger
from lnt.lnttool.common import submit_options
-import builtintest
+from . import builtintest
class TestModule(object):
More information about the llvm-commits
mailing list