Bug 1382775 - Add tools/tryselect to flake8 linter, r=chmanchester
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Mon, 17 Jul 2017 21:40:15 -0400
changeset 419335 7f34be19c84bda97a3f652832582f2f5c24c1d8b
parent 419334 27b5181a3c773020e5e6b659c0d951e75d7ee581
child 419336 c94bf66df1229bdc9f507bbd8ff44ac65c7d2911
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1382775
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382775 - Add tools/tryselect to flake8 linter, r=chmanchester This also fixes a handful of lint errors in the mach_commands.py and syntax.py files. MozReview-Commit-ID: 6nXz87ch3z4
tools/lint/flake8.yml
tools/tryselect/mach_commands.py
tools/tryselect/selectors/syntax.py
--- a/tools/lint/flake8.yml
+++ b/tools/lint/flake8.yml
@@ -10,14 +10,15 @@ flake8:
         - testing/marionette/harness
         - testing/marionette/puppeteer
         - testing/mozbase
         - testing/mochitest
         - testing/talos/
         - tools/git
         - tools/lint
         - tools/mercurial
+        - tools/tryselect
         - toolkit/components/telemetry
     exclude:
         - testing/mochitest/pywebsocket
     extensions: ['py']
     type: external
     payload: flake8_:lint
--- a/tools/tryselect/mach_commands.py
+++ b/tools/tryselect/mach_commands.py
@@ -170,17 +170,19 @@ class PushToTry(MachCommandBase):
 
         """
 
         from mozbuild.testing import TestResolver
         from tryselect.selectors.syntax import AutoTry
 
         print("mach try is under development, please file bugs blocking 1149670.")
 
-        resolver_func = lambda: self._spawn(TestResolver)
+        def resolver_func():
+            return self._spawn(TestResolver)
+
         at = AutoTry(self.topsrcdir, resolver_func, self._mach_context)
 
         if kwargs["list"]:
             at.list_presets()
             sys.exit()
 
         if kwargs["load"] is not None:
             defaults = at.load_config(kwargs["load"])
--- a/tools/tryselect/selectors/syntax.py
+++ b/tools/tryselect/selectors/syntax.py
@@ -1,14 +1,13 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import argparse
-import itertools
 import os
 import re
 import subprocess
 import sys
 import which
 
 from collections import defaultdict
 
@@ -16,44 +15,48 @@ import ConfigParser
 
 
 def arg_parser():
     parser = argparse.ArgumentParser()
     parser.add_argument('paths', nargs='*', help='Paths to search for tests to run on try.')
     parser.add_argument('-b', '--build', dest='builds', default='do',
                         help='Build types to run (d for debug, o for optimized).')
     parser.add_argument('-p', '--platform', dest='platforms', action='append',
-                        help='Platforms to run (required if not found in the environment as AUTOTRY_PLATFORM_HINT).')
+                        help='Platforms to run (required if not found in the environment as '
+                             'AUTOTRY_PLATFORM_HINT).')
     parser.add_argument('-u', '--unittests', dest='tests', action='append',
                         help='Test suites to run in their entirety.')
     parser.add_argument('-t', '--talos', dest='talos', action='append',
                         help='Talos suites to run.')
     parser.add_argument('-j', '--jobs', dest='jobs', action='append',
                         help='Job tasks to run.')
     parser.add_argument('--tag', dest='tags', action='append',
                         help='Restrict tests to the given tag (may be specified multiple times).')
     parser.add_argument('--and', action='store_true', dest='intersection',
-                        help='When -u and paths are supplied run only the intersection of the tests specified by the two arguments.')
+                        help='When -u and paths are supplied run only the intersection of the '
+                             'tests specified by the two arguments.')
     parser.add_argument('--no-push', dest='push', action='store_false',
                         help='Do not push to try as a result of running this command (if '
                         'specified this command will only print calculated try '
                         'syntax and selection info).')
     parser.add_argument('--save', dest='save', action='store',
                         help='Save the command line arguments for future use with --preset.')
     parser.add_argument('--preset', dest='load', action='store',
-                        help='Load a saved set of arguments. Additional arguments will override saved ones.')
+                        help='Load a saved set of arguments. Additional arguments will override '
+                             'saved ones.')
     parser.add_argument('--list', action='store_true',
                         help='List all saved try strings')
     parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', default=False,
                         help='Print detailed information about the resulting test selection '
                         'and commands performed.')
     for arg, opts in AutoTry.pass_through_arguments.items():
         parser.add_argument(arg, **opts)
     return parser
 
+
 class TryArgumentTokenizer(object):
     symbols = [("seperator", ","),
                ("list_start", "\["),
                ("list_end", "\]"),
                ("item", "([^,\[\]\s][^,\[\]]+)"),
                ("space", "\s+")]
     token_re = re.compile("|".join("(?P<%s>%s)" % item for item in symbols))
 
@@ -61,16 +64,17 @@ class TryArgumentTokenizer(object):
         for match in self.token_re.finditer(data):
             symbol = match.lastgroup
             data = match.group(symbol)
             if symbol == "space":
                 pass
             else:
                 yield symbol, data
 
+
 class TryArgumentParser(object):
     """Simple three-state parser for handling expressions
     of the from "foo[sub item, another], bar,baz". This takes
     input from the TryArgumentTokenizer and runs through a small
     state machine, returning a dictionary of {top-level-item:[sub_items]}
     i.e. the above would result in
     {"foo":["sub item", "another"], "bar": [], "baz": []}
     In the case of invalid input a ValueError is raised."""
@@ -136,21 +140,23 @@ class TryArgumentParser(object):
         else:
             raise ValueError
 
     def after_list_end_state(self):
         self.expect("seperator")
         self.consume()
         self.state = self.item_state
 
+
 def parse_arg(arg):
     tokenizer = TryArgumentTokenizer()
     parser = TryArgumentParser()
     return parser.parse(tokenizer.tokenize(arg))
 
+
 class AutoTry(object):
 
     # Maps from flavors to the job names needed to run that flavour
     flavor_jobs = {
         'mochitest': ['mochitest-1', 'mochitest-e10s-1'],
         'xpcshell': ['xpcshell'],
         'chrome': ['mochitest-o'],
         'browser-chrome': ['mochitest-browser-chrome-1',
@@ -436,22 +442,22 @@ class AutoTry(object):
             }
             print(message.format(**string_format))
             del suites['all']
             suites.update({suite_name: None for suite_name in non_compiled_suites})
 
         if suites:
             parts.append("-u")
             parts.append(",".join("%s%s" % (k, "[%s]" % ",".join(v) if v else "")
-                                  for k,v in sorted(suites.items())))
+                                  for k, v in sorted(suites.items())))
 
         if talos:
             parts.append("-t")
             parts.append(",".join("%s%s" % (k, "[%s]" % ",".join(v) if v else "")
-                                  for k,v in sorted(talos.items())))
+                                  for k, v in sorted(talos.items())))
 
         if jobs:
             parts.append("-j")
             parts.append(",".join(jobs))
 
         if tags:
             parts.append(' '.join('--tag %s' % t for t in tags))