@@ -42,7 +42,7 @@ def measure_lines_of_code(
4242 exclude_paths : list [str ],
4343 exclude_dirs : list [str ],
4444 include_exts : list [str ],
45- ) -> dict [ str , int ] :
45+ ) -> pl . DataFrame :
4646 if not downloads_dir .exists () or not any (downloads_dir .iterdir ()):
4747 url = "https://github.com/" + github
4848 subprocess .run (["git" , "clone" , url , downloads_dir ], check = True )
@@ -72,7 +72,13 @@ def measure_lines_of_code(
7272 raise RuntimeError (
7373 f"Failed to parse cloc output as JSON: { result .stdout } "
7474 ) from e
75- return cloc_output ["SUM" ]
75+
76+ df = pl .DataFrame (cloc_output )
77+ df = df .select (
78+ pl .col (c ).struct .field ("code" ).alias (c ) for c in df .columns if c != "header"
79+ )
80+
81+ return df
7682
7783
7884def main ():
@@ -87,29 +93,42 @@ def main():
8793 always_exclude_dirs = config ["always_exclude_dirs" ]
8894 valid_extensions = config ["valid_extensions" ]
8995
90- results = {}
96+ results = pl . DataFrame ()
9197
9298 for modeling_interface , mi_config in config ["modeling_interfaces" ].items ():
93- results [modeling_interface ] = measure_lines_of_code (
94- mi_config ["github" ],
95- cwd / "downloads" / modeling_interface ,
96- include_paths = mi_config ["include_paths" ],
97- exclude_paths = mi_config .get ("exclude_paths" , []),
98- include_exts = valid_extensions ,
99- exclude_dirs = always_exclude_dirs ,
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" ,
100112 )
101113
102- results = pl .DataFrame (results , orient = "row" )
103- results = results .unpivot (
104- on = results .columns , variable_name = "modeling_interface" , value_name = "data"
105- )
106- results = results .select ("modeling_interface" , pl .col ("data" ).struct .unnest ()).sort (
107- "code" , descending = True
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 )
108128 )
109129
110- results .write_csv (cwd / "results.csv" )
111-
112130 print (results )
131+ results .write_csv (cwd / "results.csv" )
113132
114133
115134if __name__ == "__main__" :
0 commit comments