Bug 1302786 - Support filtering output from task-graph generation; r?dustin draft bug-1302786-2
authorHammad Akhtar <hammad13060@iiitd.ac.in>
Wed, 16 Nov 2016 00:06:42 +0530
branchbug-1302786-2
changeset 894616 dc79b735fafb78317f4b7ff409995a43a193b0c2
parent 894615 9d857c040a96dd05b9065e255cd4a9dbbfbab2bf
child 894617 471eaa285bcd7a1d58c69ce112c52bd9491484aa
child 894622 82d643c5341a289deb238219b199500aa99b912c
child 894647 191db05218fbcba255b85c26dfa65562f99345de
push id155136
push userhammad13060@iiitd.ac.in
push dateWed, 16 Nov 2016 15:55:27 +0000
treeherdertry@471eaa285bcd [default view] [failures only]
reviewersdustin
bugs1302786
milestone52.0a1
Bug 1302786 - Support filtering output from task-graph generation; r?dustin MozReview-Commit-ID: A7BSsNKpOEj
taskcluster/mach_commands.py
taskcluster/taskgraph/taskgraph.py
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -6,16 +6,17 @@
 
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import json
 import logging
 import sys
 import traceback
+import re
 
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
     SubCommand,
 )
 
@@ -225,30 +226,55 @@ class MachCommands(MachCommandBase):
             target_tasks_method = taskgraph.target_tasks.get_method(target_tasks_method)
             tgg = taskgraph.generator.TaskGraphGenerator(
                 root_dir=options['root'],
                 parameters=parameters,
                 target_tasks_method=target_tasks_method)
 
             tg = getattr(tgg, graph_attr)
             show_method = getattr(self, 'show_taskgraph_' + (options['format'] or 'labels'))
-            tg = TaskGraph.get_filtered_taskgraph(tg, options["tasks_regex"])
+            tg = self.get_filtered_taskgraph(tg, options["tasks_regex"])
             show_method(tg)
         except Exception:
             traceback.print_exc()
             sys.exit(1)
 
     def show_taskgraph_labels(self, taskgraph):
         for label in taskgraph.graph.visit_postorder():
             print(label)
 
     def show_taskgraph_json(self, taskgraph):
         print(json.dumps(taskgraph.to_json(),
               sort_keys=True, indent=2, separators=(',', ': ')))
 
+    def get_filtered_taskgraph(self, taskgraph, tasksregex):
+        from taskgraph.graph import Graph
+        from taskgraph.taskgraph import TaskGraph
+        """
+        This class method filters all the tasks on basis of a regular expression
+        and returns a new TaskGraph object
+        """
+        # return original taskgraph if no regular expression is passed
+        if not tasksregex:
+            return taskgraph
+        named_links_dict = taskgraph.graph.named_links_dict()
+        filteredtasks = {}
+        filterededges = set()
+        regexprogram = re.compile(tasksregex)
+
+        for key in taskgraph.graph.visit_postorder():
+            task = taskgraph.tasks[key]
+            if regexprogram.match(task.label):
+                filteredtasks[key] = task
+                for depname, dep in named_links_dict.iteritems():
+                    if regexprogram.match(dep):
+                        filterededges.add((key, dep, depname))
+        filtered_taskgraph = TaskGraph(filteredtasks, Graph(set(filteredtasks), filterededges))
+        return filtered_taskgraph
+
 
 @CommandProvider
 class TaskClusterImagesProvider(object):
     @Command('taskcluster-load-image', category="ci",
              description="Load a pre-built Docker image")
     @CommandArgument('--task-id',
                      help="Load the image at public/image.tar in this task,"
                           "rather than searching the index")
--- a/taskcluster/taskgraph/taskgraph.py
+++ b/taskcluster/taskgraph/taskgraph.py
@@ -1,16 +1,15 @@
 # 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/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import os
-import re
 
 from .graph import Graph
 from .util.python_path import find_object
 
 TASKCLUSTER_QUEUE_URL = "https://queue.taskcluster.net/v1/task/"
 GECKO = os.path.realpath(os.path.join(__file__, '..', '..', '..'))
 
 
@@ -76,32 +75,8 @@ class TaskGraph(object):
             task_kind = find_object(implementation)
             tasks[key] = task_kind.from_json(value)
             if 'task_id' in value:
                 tasks[key].task_id = value['task_id']
             for depname, dep in value['dependencies'].iteritems():
                 edges.add((key, dep, depname))
         task_graph = cls(tasks, Graph(set(tasks), edges))
         return tasks, task_graph
-
-    @classmethod
-    def get_filtered_taskgraph(cls, taskgraph, tasksregex):
-        """
-        This class method filters all the tasks on basis of a regular expression
-        and returns a new TaskGraph object
-        """
-        # return original taskgraph if no regular expression is passed
-        if not tasksregex:
-            return taskgraph
-        named_links_dict = taskgraph.graph.named_links_dict()
-        filteredtasks = {}
-        filterededges = set()
-        regexprogram = re.compile(tasksregex)
-
-        for key in taskgraph.graph.visit_postorder():
-            task = taskgraph.tasks[key]
-            if regexprogram.match(task.label):
-                filteredtasks[key] = task
-                for depname, dep in named_links_dict.iteritems():
-                    if regexprogram.match(dep):
-                        filterededges.add((key, dep, depname))
-        filtered_taskgraph = cls(filteredtasks, Graph(set(filteredtasks), filterededges))
-        return filtered_taskgraph