code: def group_rules_by_time_needed(
      rules: List[BazelRule],
  ) -> List[Tuple[float, List[BazelRule]]]:
      """
      Return a list of tuples of (timeout in seconds, list of rules)
      sorted descending.
      """
      grouped_rules = defaultdict(list)
      for rule in rules:
          grouped_rules[rule.actual_timeout_s].append(rule)
      for timeout in grouped_rules:
          grouped_rules[timeout] = sorted(grouped_rules[timeout])
      return sorted(
          grouped_rules.items(), key=lambda x: x[0], reverse=True
      )
  
imports: from collections import defaultdict
  from dataclasses import dataclass
  from typing import Iterable, List, Optional, Set, Tuple
  import argparse
  import os
  import re
  import shlex
  import subprocess
  import sys
  import xml.etree.ElementTree
label_desc: Use image node_id 8 for calling a global function with example usage: group_rules_by_time_needed(rules) and returns: sorted