99lib_path = os .path .abspath (os .path .join (current_dir , ".." , ".." ))
1010sys .path .insert (0 , lib_path )
1111
12+ import subprocess
13+
14+ def load_exclude_authors (file_path ):
15+ path = Path (file_path )
16+ if not path .exists ():
17+ return []
18+ with open (path , "r" , encoding = "utf-8" ) as f :
19+ return [line .strip () for line in f if line .strip ()]
20+
21+ def get_last_commit_excluding (exclude_file ):
22+ exclude_authors = set (load_exclude_authors (exclude_file ))
23+
24+ logs = subprocess .check_output ([
25+ "git" , "log" ,
26+ "--pretty=format:%H|%ae" , # commit hash | author email
27+ ]).decode ("utf-8" ).splitlines ()
28+
29+ for line in logs :
30+ commit , email = line .split ("|" , 1 )
31+ if email not in exclude_authors :
32+ return commit
33+ return None
34+
1235def classify_file_category (path ):
1336
1437 relative_path = Path (path ).relative_to (lib_path )
@@ -25,7 +48,6 @@ def classify_file_category(path):
2548
2649
2750def fetch_option_flags (flags ):
28- # flags = genflags.parser.flags
2951 flag_list = []
3052
3153 for flag in flags :
@@ -42,6 +64,7 @@ def fetch_option_flags(flags):
4264
4365def fetch_all_files ():
4466 main_files = [
67+ os .path .join (lib_path , "main.py" ),
4568 os .path .join (lib_path , "linear_trainer.py" ),
4669 os .path .join (lib_path , "torch_trainer.py" )
4770 ]
@@ -61,13 +84,27 @@ def find_config_usages_in_file(file_path, allowed_keys):
6184
6285 category , path = classify_file_category (file_path )
6386
87+ if file_path .endswith ("main.py" ):
88+ for idx in range (len (lines )):
89+ if lines [idx ].startswith ("def main(" ):
90+ lines = lines [idx :]
91+ main_start = idx
92+ break
93+ for i , line in enumerate (lines [1 :]):
94+ if line and line [0 ] not in (" " , "\t " ) and line .strip () != "" :
95+ lines = lines [:i ]
96+ break
97+
6498 for i , line in enumerate (lines , start = 1 ):
6599 matches = pattern .findall (line )
66100 for key in matches :
67101 if key in allowed_keys :
68102 if key not in detailed_results :
69103 detailed_results [key ] = {"file" : path , "lines" : []}
70- detailed_results [key ]["lines" ].append (str (i ))
104+ if file_path .endswith ("main.py" ):
105+ detailed_results [key ]["lines" ].append (str (i + main_start ))
106+ else :
107+ detailed_results [key ]["lines" ].append (str (i ))
71108
72109 return detailed_results
73110
@@ -125,6 +162,7 @@ def classify(raw_flags):
125162 for flag in flags :
126163 if flag ["category" ] not in result :
127164 result [flag ["category" ]] = []
165+
128166 result [flag ["category" ]].append ({"name" : flag ["name" ].replace ("--" , r"\-\-" ), "description" : flag ["description" ]})
129167
130168 result ["details" ] = []
@@ -134,4 +172,4 @@ def classify(raw_flags):
134172 for i in v [1 :]:
135173 result ["details" ].append ({"name" : "" , "file" : i ["file" ], "location" : ", " .join (i ["lines" ])})
136174
137- return result
175+ return result
0 commit comments