66from remove_runnable_code import remove_runnable_code
77
88
9+ # Calculate repo base dir
10+ REPO_BASE_DIR = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
11+
912def get_all_files (encoding = "utf-8" ) -> List [str ]:
1013 sources = [
1114 "beginner_source" ,
@@ -16,11 +19,12 @@ def get_all_files(encoding="utf-8") -> List[str]:
1619 ]
1720 cmd = ["find" ] + sources + ["-name" , "*.py" , "-not" , "-path" , "*/data/*" ]
1821
19- return run (cmd , capture_output = True ).stdout .decode (encoding ).splitlines ()
22+ return run (cmd , capture_output = True , cwd = REPO_BASE_DIR ).stdout .decode (encoding ).splitlines ()
2023
2124
2225def calculate_shards (all_files , num_shards = 20 ):
23- metadata = json .load (open (".jenkins/metadata.json" ))
26+ with open (os .path .join (REPO_BASE_DIR , ".jenkins" , "metadata.json" )) as fp :
27+ metadata = json .load (fp )
2428 sharded_files = [(0.0 , []) for _ in range (num_shards )]
2529
2630 def get_duration (file ):
@@ -47,9 +51,7 @@ def add_to_shard(i, filename):
4751 # so we'll add all the jobs that need this machine to the 0th worker
4852 add_to_shard (0 , filename )
4953
50- all_other_files = list (
51- filter (lambda x : x not in needs_gpu_nvidia_small_multi , all_files )
52- )
54+ all_other_files = [x for x in all_files if x not in needs_gpu_nvidia_small_multi ]
5355
5456 sorted_files = sorted (all_other_files , key = get_duration , reverse = True ,)
5557
@@ -58,23 +60,23 @@ def add_to_shard(i, filename):
5860 0
5961 ]
6062 add_to_shard (min_shard_index , filename )
61- return list ( map ( lambda x : x [1 ], sharded_files ))
63+ return [ x [1 ] for x in sharded_files ]
6264
6365
64- def remove_other_files (all_files , files_to_run ):
66+ def remove_other_files (all_files , files_to_run ) -> None :
6567 for file in all_files :
6668 if file not in files_to_run :
6769 remove_runnable_code (file , file )
6870
6971
70- def main ():
72+ def main () -> None :
7173 num_shards = int (os .environ .get ("NUM_WORKERS" , 20 ))
7274 shard_num = int (os .environ .get ("WORKER_ID" , 0 ))
7375
7476 all_files = get_all_files ()
7577 files_to_run = calculate_shards (all_files , num_shards = num_shards )[shard_num ]
7678 remove_other_files (all_files , files_to_run )
77- stripped_file_names = list ( map ( lambda x : Path (x ).stem , files_to_run ))
79+ stripped_file_names = [ Path (x ).stem for x in files_to_run ]
7880 print (" " .join (stripped_file_names ))
7981
8082
0 commit comments