88import yaml
99
1010
11- def check_installed ():
12- try :
13- subprocess .run (
14- ["git" , "--version" ],
15- check = True ,
16- stdout = subprocess .DEVNULL ,
17- stderr = subprocess .DEVNULL ,
18- )
19- except subprocess .CalledProcessError as e :
20- raise RuntimeError (
21- "Git is not installed. Please install Git to run this script."
22- ) from e
11+ def main ():
12+ cwd = Path (__file__ ).parent
2313
24- try :
25- subprocess .run (
26- ["cloc" , "--version" ],
27- check = True ,
28- stdout = subprocess .DEVNULL ,
29- stderr = subprocess .DEVNULL ,
14+ # Read config.yaml
15+ with open (cwd / "config.yaml" ) as file :
16+ config = yaml .safe_load (file )
17+
18+ results = pl .DataFrame ()
19+
20+ for modeling_interface , mi_config in config ["modeling_interfaces" ].items ():
21+ github = mi_config ["github" ].lower ()
22+ results = pl .concat (
23+ [
24+ results ,
25+ measure_lines_of_code (
26+ github ,
27+ cwd / "downloads" / github .partition ("/" )[2 ],
28+ include_paths = mi_config ["include_paths" ],
29+ exclude_paths = mi_config .get ("exclude_paths" , []),
30+ include_exts = config ["valid_extensions" ],
31+ exclude_dirs = config ["always_exclude_dirs" ],
32+ ).with_columns (modeling_interface = pl .lit (modeling_interface )),
33+ ],
34+ how = "diagonal" ,
3035 )
31- except subprocess .CalledProcessError as e :
32- raise RuntimeError (
33- "cloc is not installed. Please install cloc to run this script."
34- ) from e
36+
37+ results = results .with_columns (
38+ (
39+ pl .col ("C++" ).fill_null (0 )
40+ + pl .col ("C/C++ Header" ).fill_null (0 )
41+ + pl .col ("C" ).fill_null (0 )
42+ ).alias ("C/C++" )
43+ ).drop ("C/C++ Header" , "C" , "C++" )
44+ results = results .select (
45+ "modeling_interface" ,
46+ * [col for col in results .columns if col not in ("modeling_interface" , "SUM" )],
47+ total = "SUM" ,
48+ ).sort ("total" )
49+ results = results .with_columns (
50+ factor = (
51+ pl .col ("total" )
52+ / results .filter (modeling_interface = "pyoframe" )["total" ].item ()
53+ ).round (1 )
54+ )
55+ print (results )
56+
57+ results .write_csv (cwd / "results.csv" )
3558
3659
3760def measure_lines_of_code (
38- github ,
61+ github : str ,
3962 downloads_dir : Path ,
4063 * ,
4164 include_paths : list [str ],
@@ -47,7 +70,6 @@ def measure_lines_of_code(
4770 url = "https://github.com/" + github
4871 subprocess .run (["git" , "clone" , url , downloads_dir ], check = True )
4972
50- # run cloc
5173 cmd = ["cloc" ]
5274 cmd += include_paths
5375 if exclude_paths :
@@ -81,55 +103,5 @@ def measure_lines_of_code(
81103 return df
82104
83105
84- def main ():
85- check_installed ()
86-
87- cwd = Path (__file__ ).parent
88-
89- # Read config.yaml
90- with open (cwd / "config.yaml" ) as file :
91- config = yaml .safe_load (file )
92-
93- always_exclude_dirs = config ["always_exclude_dirs" ]
94- valid_extensions = config ["valid_extensions" ]
95-
96- results = pl .DataFrame ()
97-
98- for modeling_interface , mi_config in config ["modeling_interfaces" ].items ():
99- results = pl .concat (
100- [
101- results ,
102- measure_lines_of_code (
103- mi_config ["github" ],
104- cwd / "downloads" / modeling_interface ,
105- include_paths = mi_config ["include_paths" ],
106- exclude_paths = mi_config .get ("exclude_paths" , []),
107- include_exts = valid_extensions ,
108- exclude_dirs = always_exclude_dirs ,
109- ).with_columns (modeling_interface = pl .lit (modeling_interface )),
110- ],
111- how = "diagonal" ,
112- )
113-
114- # reorder columns
115- results = results .with_columns (
116- (pl .col ("C++" ) + pl .col ("C/C++ Header" )).alias ("C++" )
117- ).drop ("C/C++ Header" )
118- results = results .select (
119- "modeling_interface" ,
120- * [col for col in results .columns if col not in ("modeling_interface" , "SUM" )],
121- total = "SUM" ,
122- ).sort ("total" )
123- results = results .with_columns (
124- factor = (
125- pl .col ("total" )
126- / results .filter (modeling_interface = "pyoframe" )["total" ].item ()
127- ).round (1 )
128- )
129-
130- print (results )
131- results .write_csv (cwd / "results.csv" )
132-
133-
134106if __name__ == "__main__" :
135107 main ()
0 commit comments