Bug 1531886 - [tryselect] Handle templates in mach_commands.py, r=gbrown
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 05 Mar 2019 23:48:31 +0000
changeset 520559 ba832d587ae117729d39b1040f1f87e2655b31ac
parent 520558 bee5219e28b23a0108073d70fe9a6854557416c6
child 520560 ac6bdcb49765b3234f32293ace73987223f65659
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1531886
milestone67.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 1531886 - [tryselect] Handle templates in mach_commands.py, r=gbrown This was previously only in the cli parser because that was the only shared place that ran for all selectors. Now that we have the 'self.run' function in mach_commands.py, we can move it there. This move is also needed to allow us to remove 'templates' from kwargs (which happens in the next commit). Depends on D22021 Differential Revision: https://phabricator.services.mozilla.com/D22022
tools/tryselect/cli.py
tools/tryselect/mach_commands.py
--- a/tools/tryselect/cli.py
+++ b/tools/tryselect/cli.py
@@ -94,17 +94,16 @@ class BaseTryParser(ArgumentParser):
             # Preset arguments are all mutually exclusive.
             if name == 'preset':
                 group = group.add_mutually_exclusive_group()
 
             for cli, kwargs in arguments:
                 group.add_argument(*cli, **kwargs)
 
         group = self.add_argument_group("template arguments")
-        self.set_defaults(templates={})
         self.templates = {t: all_templates[t]() for t in self.templates}
         for template in self.templates.values():
             template.add_arguments(group)
 
     def validate(self, args):
         if hasattr(args, 'message'):
             if args.message == 'editor':
                 if 'EDITOR' not in os.environ:
@@ -115,16 +114,9 @@ class BaseTryParser(ArgumentParser):
                     args.message = fh.read().strip()
 
             if '{msg}' not in args.message:
                 args.message = '{}\n\n{}'.format(args.message, '{msg}')
 
     def parse_known_args(self, *args, **kwargs):
         args, remainder = ArgumentParser.parse_known_args(self, *args, **kwargs)
         self.validate(args)
-
-        if self.templates:
-            for cls in self.templates.itervalues():
-                context = cls.context(**vars(args))
-                if context is not None:
-                    args.templates.update(context)
-
         return args, remainder
--- a/tools/tryselect/mach_commands.py
+++ b/tools/tryselect/mach_commands.py
@@ -142,20 +142,32 @@ class TrySelect(MachCommandBase):
                     defaults[k] = v
                 else:
                     nondefaults[k] = v
 
             kwargs = merge(defaults, preset, nondefaults)
 
         return kwargs
 
+    def handle_templates(self, **kwargs):
+        kwargs.setdefault('templates', {})
+        for cls in self.parser.templates.itervalues():
+            context = cls.context(**kwargs)
+            if context is not None:
+                kwargs['templates'].update(context)
+
+        return kwargs
+
     def run(self, **kwargs):
         if 'preset' in self.parser.common_groups:
             kwargs = self.handle_presets(**kwargs)
 
+        if self.parser.templates:
+            kwargs = self.handle_templates(**kwargs)
+
         mod = importlib.import_module('tryselect.selectors.{}'.format(self.subcommand))
         return mod.run(**kwargs)
 
     @Command('try',
              category='ci',
              description='Push selected tasks to the try server',
              parser=generic_parser)
     def try_default(self, argv=None, **kwargs):