3838from codeplag .types import (
3939 ASTFeatures ,
4040 CompareInfo ,
41+ ExitCode ,
4142 Extension ,
4243 Flag ,
4344 MaxDepth ,
@@ -151,7 +152,7 @@ def check(
151152 github_files : list [str ] | None = None ,
152153 github_project_folders : list [str ] | None = None ,
153154 github_user : str = "" ,
154- ) -> None :
155+ ) -> ExitCode :
155156 if files is None :
156157 files = []
157158 if directories is None :
@@ -167,16 +168,17 @@ def check(
167168 features_from_gh_files = self .features_getter .get_from_github_files (github_files )
168169
169170 logger .info ("Starting searching for plagiarism ..." )
171+ exit_code = ExitCode .EXIT_SUCCESS
170172 if self .mode == "many_to_many" :
171- self .__many_to_many_check (
173+ exit_code = self .__many_to_many_check (
172174 features_from_files ,
173175 directories ,
174176 features_from_gh_files ,
175177 github_project_folders ,
176178 github_user ,
177179 )
178180 elif self .mode == "one_to_one" :
179- self .__one_to_one_check (
181+ exit_code = self .__one_to_one_check (
180182 features_from_files ,
181183 directories ,
182184 features_from_gh_files ,
@@ -187,6 +189,7 @@ def check(
187189 logger .info ("Ending searching for plagiarism ..." )
188190 if isinstance (self .reporter , CSVReporter ):
189191 self .reporter ._write_df_to_fs ()
192+ return exit_code
190193
191194 def __many_to_many_check (
192195 self : Self ,
@@ -195,7 +198,7 @@ def __many_to_many_check(
195198 features_from_gh_files : list [ASTFeatures ],
196199 github_project_folders : list [str ],
197200 github_user : str ,
198- ) -> None :
201+ ) -> ExitCode :
199202 works : list [ASTFeatures ] = []
200203 works .extend (features_from_files )
201204 works .extend (self .features_getter .get_from_dirs (directories ))
@@ -212,15 +215,19 @@ def __many_to_many_check(
212215 iterations ,
213216 )
214217 self .progress = Progress (iterations )
218+ exit_code = ExitCode .EXIT_SUCCESS
215219 with ProcessPoolExecutor (max_workers = self .workers ) as executor :
216220 processing : list [ProcessingWorks ] = []
217221 futures : set [Future ] = set ()
218222 for i , work1 in enumerate (works ):
219223 for j , work2 in enumerate (works ):
220224 if i <= j :
221225 continue
222- self ._do_step (executor , processing , futures , work1 , work2 )
223- self ._handle_completed_futures (processing , futures )
226+ exit_code = ExitCode (
227+ exit_code | self ._do_step (executor , processing , futures , work1 , work2 )
228+ )
229+ exit_code = ExitCode (exit_code | self ._handle_completed_futures (processing , futures ))
230+ return exit_code
224231
225232 def __one_to_one_check (
226233 self : Self ,
@@ -229,7 +236,7 @@ def __one_to_one_check(
229236 features_from_gh_files : list [ASTFeatures ],
230237 github_project_folders : list [str ],
231238 github_user : str ,
232- ) -> None :
239+ ) -> ExitCode :
233240 combined_elements = filter (
234241 bool ,
235242 (
@@ -253,6 +260,7 @@ def __one_to_one_check(
253260 )
254261 self .progress = ComplexProgress (iterations )
255262 cases = combinations (combined_elements , r = 2 )
263+ exit_code = ExitCode .EXIT_SUCCESS
256264 with ProcessPoolExecutor (max_workers = self .workers ) as executor :
257265 processing : list [ProcessingWorks ] = []
258266 futures : set [Future ] = set ()
@@ -269,8 +277,11 @@ def __one_to_one_check(
269277 self .progress .add_internal_progress (internal_iterations )
270278 for work1 in first_sequence :
271279 for work2 in second_sequence :
272- self ._do_step (executor , processing , futures , work1 , work2 )
273- self ._handle_completed_futures (processing , futures )
280+ exit_code = ExitCode (
281+ exit_code | self ._do_step (executor , processing , futures , work1 , work2 )
282+ )
283+ exit_code = ExitCode (exit_code | self ._handle_completed_futures (processing , futures ))
284+ return exit_code
274285
275286 def _do_step (
276287 self : Self ,
@@ -279,10 +290,10 @@ def _do_step(
279290 futures : set [Future ],
280291 work1 : ASTFeatures ,
281292 work2 : ASTFeatures ,
282- ) -> None :
293+ ) -> ExitCode :
283294 if work1 .filepath == work2 .filepath :
284295 _print_pretty_progress_if_need_and_increase (self .progress , self .workers )
285- return
296+ return ExitCode . EXIT_SUCCESS
286297
287298 work1 , work2 = sorted ([work1 , work2 ])
288299 metrics = None
@@ -293,23 +304,24 @@ def _do_step(
293304 future .id = len (processing ) # type: ignore
294305 futures .add (future )
295306 processing .append (ProcessingWorks (work1 , work2 ))
296- return
307+ return ExitCode . EXIT_SUCCESS
297308 self ._handle_compare_result (work1 , work2 , metrics )
298309 _print_pretty_progress_if_need_and_increase (self .progress , self .workers )
310+ return ExitCode .EXIT_FOUND_SIM
299311
300312 def _handle_compare_result (
301313 self : Self ,
302314 work1 : ASTFeatures ,
303315 work2 : ASTFeatures ,
304316 metrics : CompareInfo ,
305317 save : bool = False ,
306- ) -> None :
318+ ) -> ExitCode :
307319 if metrics .structure is None :
308- return
320+ return ExitCode . EXIT_SUCCESS
309321 if self .reporter and save :
310322 self .reporter .save_result (work1 , work2 , metrics )
311323 if self .short_output :
312- return
324+ return ExitCode . EXIT_FOUND_SIM
313325
314326 if self .threshold and (metrics .structure .similarity * 100 ) <= self .threshold :
315327 print_compare_result (work1 , work2 , metrics )
@@ -324,19 +336,25 @@ def _handle_compare_result(
324336 work2 .head_nodes ,
325337 ),
326338 )
339+ return ExitCode .EXIT_FOUND_SIM
327340
328341 def _handle_completed_futures (
329342 self : Self ,
330343 processing : list [ProcessingWorks ],
331344 futures : set [Future ],
332- ) -> None :
345+ ) -> ExitCode :
346+ exit_code = ExitCode .EXIT_SUCCESS
333347 for future in as_completed (futures ):
334348 metrics : CompareInfo = future .result ()
335349 proc_works_info = processing [future .id ] # type: ignore
336- self ._handle_compare_result (
337- proc_works_info .work1 , proc_works_info .work2 , metrics , save = True
350+ exit_code = ExitCode (
351+ exit_code
352+ | self ._handle_compare_result (
353+ proc_works_info .work1 , proc_works_info .work2 , metrics , save = True
354+ )
338355 )
339356 _print_pretty_progress_if_need_and_increase (self .progress , self .workers )
357+ return exit_code
340358
341359 def _create_future_compare (
342360 self : Self ,
0 commit comments