11import os
22import json
33import argparse
4- from typing import List , Dict , Tuple
4+ from typing import List , Dict
55
66# ---------------------------------------------------------
7- # THE VIP LIST: Known mammoths that must bypass the queue
7+ # THE VIP LIST: These will get their own dedicated isolated VMs
88# ---------------------------------------------------------
99MAMMOTH_OVERRIDES = {
1010 "google-cloud-spanner" : 9999 ,
1515}
1616
1717def calculate_package_weight (pkg_path : str ) -> int :
18- """
19- Determines computational weight. Mammoths get massive artificial weights
20- to guarantee they are processed first.
21- """
2218 pkg_name = os .path .basename (os .path .normpath (pkg_path ))
2319 if pkg_name in MAMMOTH_OVERRIDES :
2420 return MAMMOTH_OVERRIDES [pkg_name ]
2521
2622 base_weight = 1
27-
2823 meta_path = os .path .join (pkg_path , ".repo-metadata.json" )
2924 if os .path .isfile (meta_path ):
3025 try :
@@ -34,7 +29,6 @@ def calculate_package_weight(pkg_path: str) -> int:
3429 except Exception :
3530 pass
3631
37- # Fallback for standard packages: roughly estimate by test file count
3832 test_dir = os .path .join (pkg_path , "tests" )
3933 if os .path .isdir (test_dir ):
4034 for root , _ , files in os .walk (test_dir ):
@@ -48,8 +42,6 @@ def create_balanced_buckets(packages: List[str], max_buckets: int) -> List[Dict]
4842 return []
4943
5044 pkg_weights = [(pkg , calculate_package_weight (pkg )) for pkg in valid_pkgs ]
51-
52- # Sort heaviest to lightest. Mammoths (9999) will always be at the front.
5345 pkg_weights .sort (key = lambda x : x [1 ], reverse = True )
5446
5547 num_buckets = min (len (valid_pkgs ), max_buckets )
@@ -60,7 +52,25 @@ def create_balanced_buckets(packages: List[str], max_buckets: int) -> List[Dict]
6052 lightest ["packages" ].append (pkg )
6153 lightest ["total_weight" ] += weight
6254
63- return [{"id" : b ["id" ], "packages" : " " .join (b ["packages" ])} for b in buckets if b ["packages" ]]
55+ # Build the final output payload
56+ final_output = []
57+ for b in buckets :
58+ if not b ["packages" ]:
59+ continue
60+
61+ # Clean UI labels for isolated VIPs
62+ first_pkg_name = os .path .basename (os .path .normpath (b ["packages" ][0 ]))
63+ if first_pkg_name in MAMMOTH_OVERRIDES :
64+ ui_label = first_pkg_name .replace ("google-cloud-" , "" )
65+ else :
66+ ui_label = f"Bucket { b ['id' ]} "
67+
68+ final_output .append ({
69+ "id" : ui_label ,
70+ "packages" : " " .join (b ["packages" ])
71+ })
72+
73+ return final_output
6474
6575def main ():
6676 parser = argparse .ArgumentParser ()
@@ -82,4 +92,4 @@ def main():
8292 print (json .dumps (buckets , indent = 2 ))
8393
8494if __name__ == "__main__" :
85- main ()
95+ main ()
0 commit comments