[LNT] r307805 - Remove flask dependency from testing.util

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 09:14:57 PDT 2017


Author: matze
Date: Wed Jul 12 09:14:57 2017
New Revision: 307805

URL: http://llvm.org/viewvc/llvm-project?rev=307805&view=rev
Log:
Remove flask dependency from testing.util

Providing the visible_note() function and playing games with global
flask state in unrelated portions of LNT code is bad style.  Let's keep
the flash()ing to lnt.server.ui and the rest slightly more side-effect
free.

Modified:
    lnt/trunk/lnt/server/reporting/runs.py
    lnt/trunk/lnt/server/ui/views.py
    lnt/trunk/lnt/testing/util/commands.py

Modified: lnt/trunk/lnt/server/reporting/runs.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/reporting/runs.py?rev=307805&r1=307804&r2=307805&view=diff
==============================================================================
--- lnt/trunk/lnt/server/reporting/runs.py (original)
+++ lnt/trunk/lnt/server/reporting/runs.py Wed Jul 12 09:14:57 2017
@@ -6,7 +6,6 @@ import time
 import lnt.server.reporting.analysis
 import lnt.server.ui.app
 import lnt.util.stats
-from lnt.testing.util.commands import visible_note
 
 
 def generate_run_data(run, baseurl, num_comparison_runs=0, result=None,
@@ -33,9 +32,10 @@ def generate_run_data(run, baseurl, num_
         baseline = machine.get_baseline_run()
 
     # If the baseline is the same as the comparison run, ignore it.
+    visible_note = None
     if baseline is compare_to:
-        visible_note("Baseline and compare_to are the same: "
-                     "disabling baseline.")
+        visible_note = "Baseline and compare_to are the same: " \
+                       "disabling baseline."
         baseline = None
 
     # Gather the runs to use for statistical data.
@@ -207,6 +207,7 @@ def generate_run_data(run, baseurl, num_
         'classes': classes_,
         'start_time': start_time,
         'sri': sri,
+        'visible_note': visible_note,
     }
     return data
 

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=307805&r1=307804&r2=307805&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Wed Jul 12 09:14:57 2017
@@ -38,7 +38,7 @@ from lnt.server.reporting.analysis impor
 from lnt.server.ui.decorators import frontend, db_route, v4_route
 from lnt.server.ui.globals import db_url_for, v4_url_for
 from lnt.server.ui.regression_views import PrecomputedCR
-from lnt.server.ui.util import FLASH_DANGER, FLASH_SUCCESS
+from lnt.server.ui.util import FLASH_DANGER, FLASH_SUCCESS, FLASH_INFO
 from lnt.server.ui.util import mean
 from lnt.util import async_ops
 from lnt.server.ui.util import baseline_key, convert_revision
@@ -401,6 +401,9 @@ class V4RequestInfo(object):
             aggregation_fn=self.aggregation_fn, confidence_lv=confidence_lv,
             styles=styles, classes=classes)
         self.sri = self.data['sri']
+        note = self.data['visible_note']
+        if note:
+            flash(note, FLASH_INFO)
 
 @v4_route("/<int:id>/report")
 def v4_report(id):
@@ -1699,4 +1702,4 @@ def explode():
 @frontend.route("/gone")
 def gone():
     """This route returns 404. Used for testing 404 page."""
-    abort(404, "test")
\ No newline at end of file
+    abort(404, "test")

Modified: lnt/trunk/lnt/testing/util/commands.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/util/commands.py?rev=307805&r1=307804&r2=307805&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/util/commands.py (original)
+++ lnt/trunk/lnt/testing/util/commands.py Wed Jul 12 09:14:57 2017
@@ -1,7 +1,6 @@
 """
 Miscellaneous utilities for running "scripts".
 """
-
 import errno
 
 import os
@@ -9,25 +8,6 @@ import sys
 import time
 from lnt.util import logger
 
-try:
-    from flask import current_app, flash
-except:
-    # We may be imported from Sphinx. Don't error if current_app isn't available here -
-    # instead error when it is used.
-    pass
-# FIXME: Find a better place for this code.
-from lnt.server.ui.util import FLASH_INFO
-
-
-def visible_note(message):
-    """Log a note to the logger as well as page with a flash."""
-    logger.info(message)
-    try:
-        flash(message, FLASH_INFO)
-    except RuntimeError:
-        # We are not in a Flask environment right now (command line).
-        pass
-
 
 def timed(func):
     def timed(*args, **kw):




More information about the llvm-commits mailing list