1616import fosslight_util .constant as constant
1717from fosslight_util .set_log import init_log
1818from fosslight_util .timer_thread import TimerThread
19+ from fosslight_util .exclude import excluding_files
1920from reuse import report
2021from reuse .project import Project
2122from reuse .report import ProjectReport
2627is_windows = platform .system () == 'Windows'
2728REUSE_CONFIG_FILE = ".reuse/dep5"
2829DEFAULT_EXCLUDE_EXTENSION_FILES = [] # Exclude files from reuse
29- user_exclude_list = [] # Exclude paths from checking
3030_turn_on_exclude_config = True
3131_check_only_file_mode = False
3232error_items = []
@@ -88,7 +88,7 @@ def exclude_git_related_files(path: str) -> None:
8888 logger .warning (f"Error to get git related files : { ex } " )
8989
9090
91- def find_oss_pkg_info_and_exclude_file (path : str ) -> List [str ]:
91+ def find_oss_pkg_info_and_exclude_file (path : str , abs_path_to_exclude : List ) -> List [str ]:
9292 global DEFAULT_EXCLUDE_EXTENSION_FILES
9393 oss_pkg_info = []
9494 git_present = shutil .which ("git" )
@@ -98,13 +98,13 @@ def find_oss_pkg_info_and_exclude_file(path: str) -> List[str]:
9898
9999 try :
100100 for root , dirs , files in os .walk (path ):
101- if os .path .abspath (root ) in user_exclude_list :
101+ if os .path .abspath (root ) in abs_path_to_exclude :
102102 continue
103103 for dir in dirs :
104104 # For hidden folders
105105 dir_path = os .path .join (root , dir )
106106 dir_abs_path = os .path .abspath (dir_path )
107- if any (os .path .commonpath ([dir_abs_path , exclude_path ]) == exclude_path for exclude_path in user_exclude_list ):
107+ if any (os .path .commonpath ([dir_abs_path , exclude_path ]) == exclude_path for exclude_path in abs_path_to_exclude ):
108108 continue
109109 if dir .startswith ("." ):
110110 all_files_in_dir = [os .path .join (root , dir , file )
@@ -116,7 +116,7 @@ def find_oss_pkg_info_and_exclude_file(path: str) -> List[str]:
116116 for file in files :
117117 file_path = os .path .join (root , file )
118118 file_abs_path = os .path .abspath (file_path )
119- if any (os .path .commonpath ([file_abs_path , exclude_path ]) == exclude_path for exclude_path in user_exclude_list ):
119+ if any (os .path .commonpath ([file_abs_path , exclude_path ]) == exclude_path for exclude_path in abs_path_to_exclude ):
120120 continue
121121 file_lower_case = file .lower ()
122122 file_rel_path = os .path .relpath (file_path , path )
@@ -243,11 +243,11 @@ def precheck_for_files(path: str, files: List[str]) -> Tuple[List[str], List[str
243243 return missing_license_list , missing_copyright_list , prj
244244
245245
246- def precheck_for_project (path_to_find : str ) -> Tuple [List [str ], List [str ], List [str ], Project , ProjectReport ]:
246+ def precheck_for_project (path_to_find : str , abs_path_to_exclude : List ) -> Tuple [List [str ], List [str ], List [str ], Project , ProjectReport ]:
247247 missing_license = []
248248 missing_copyright = []
249249
250- oss_pkg_info_files = find_oss_pkg_info_and_exclude_file (path_to_find )
250+ oss_pkg_info_files = find_oss_pkg_info_and_exclude_file (path_to_find , abs_path_to_exclude )
251251 if _turn_on_exclude_config :
252252 need_rollback , temp_file_name , temp_dir_name = create_reuse_dep5_file (path_to_find )
253253
@@ -259,14 +259,14 @@ def precheck_for_project(path_to_find: str) -> Tuple[List[str], List[str], List[
259259 missing_license = [str (sub ) for sub in set (report .files_without_licenses )]
260260 if not path_to_find .endswith (f"{ os .sep } " ):
261261 path_to_find += f"{ os .sep } "
262- missing_license = filter_missing_list (missing_license )
262+ missing_license = filter_missing_list (missing_license , abs_path_to_exclude )
263263 missing_license = [sub .replace (path_to_find , '' , 1 ) for sub in missing_license ]
264264
265265 # File list that missing copyright text
266266 missing_copyright = [str (sub ) for sub in set (report .files_without_copyright )]
267267 if not path_to_find .endswith (f"{ os .sep } " ):
268268 path_to_find += f"{ os .sep } "
269- missing_copyright = filter_missing_list (missing_copyright )
269+ missing_copyright = filter_missing_list (missing_copyright , abs_path_to_exclude )
270270 missing_copyright = [sub .replace (path_to_find , '' , 1 ) for sub in missing_copyright ]
271271
272272 except Exception as ex :
@@ -277,11 +277,11 @@ def precheck_for_project(path_to_find: str) -> Tuple[List[str], List[str], List[
277277 return missing_license , missing_copyright , oss_pkg_info_files , project , report
278278
279279
280- def filter_missing_list (missing_list : List [str ]) -> List [str ]:
280+ def filter_missing_list (missing_list : List [str ], abs_path_to_exclude : List ) -> List [str ]:
281281 filtered_list = []
282282 for file in missing_list :
283283 abs_path = os .path .abspath (file )
284- if not any (os .path .commonpath ([abs_path , path ]) == path for path in user_exclude_list ):
284+ if not any (os .path .commonpath ([abs_path , path ]) == path for path in abs_path_to_exclude ):
285285 filtered_list .append (file )
286286 return filtered_list
287287
@@ -339,14 +339,6 @@ def get_path_to_find(target_path: str, _check_only_file_mode: bool) -> Tuple[str
339339 return path_to_find , file_to_check_list , _check_only_file_mode
340340
341341
342- def set_exclude_list (path_to_find : str , exclude_path : List [str ]):
343- global user_exclude_list
344-
345- for path in exclude_path :
346- if path .strip != "" :
347- user_exclude_list .append (os .path .abspath (os .path .join (path_to_find , path )))
348-
349-
350342def run_lint (
351343 target_path : str ,
352344 disable : bool ,
@@ -357,6 +349,7 @@ def run_lint(
357349) -> None :
358350 global _turn_on_exclude_config , _check_only_file_mode , _start_time
359351
352+ abs_path_to_exclude = []
360353 file_to_check_list = []
361354 _exit_code = 0
362355 path_to_find = ""
@@ -371,7 +364,8 @@ def run_lint(
371364 dump_error_msg (f"Error - locale : { ex } " )
372365
373366 path_to_find , file_to_check_list , _check_only_file_mode = get_path_to_find (target_path , _check_only_file_mode )
374- set_exclude_list (path_to_find , exclude_path )
367+ user_exclude_path = excluding_files (exclude_path , path_to_find )
368+ abs_path_to_exclude = [os .path .abspath (path ) for path in user_exclude_path ]
375369
376370 result_file , output_path , output_extension = create_result_file (output_file_name , format , _start_time )
377371 init (path_to_find , output_path , file_to_check_list , need_log_file , exclude_path )
@@ -389,7 +383,7 @@ def run_lint(
389383 if _check_only_file_mode :
390384 license_missing_files , copyright_missing_files , project = precheck_for_files (path_to_find , file_to_check_list )
391385 else :
392- license_missing_files , copyright_missing_files , oss_pkg_info , project , report = precheck_for_project (path_to_find )
386+ license_missing_files , copyright_missing_files , oss_pkg_info , project , report = precheck_for_project (path_to_find , abs_path_to_exclude )
393387
394388 if need_log_file :
395389 timer .stop = True
@@ -404,7 +398,7 @@ def run_lint(
404398 file_to_check_list ,
405399 error_items ,
406400 DEFAULT_EXCLUDE_EXTENSION_FILES ,
407- user_exclude_list )
401+ abs_path_to_exclude )
408402
409403 success , exit_code = write_result_file (result_file , output_extension , _exit_code ,
410404 result_item , _result_log , project , path_to_find )
0 commit comments