fosslight-source 2.1.17__py3-none-any.whl → 2.1.19__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fosslight_source/_help.py CHANGED
@@ -19,7 +19,9 @@ _HELP_MESSAGE_SOURCE_SCANNER = f"""
19
19
  -h\t\t\t Print help message
20
20
  -v\t\t\t Print FOSSLight Source Scanner version
21
21
  -m\t\t\t Print additional information for scan result on separate sheets
22
- -e <path>\t\t Path to exclude from analysis (file and directory)
22
+ -e <path>\t\t Path to exclude from analysis (files and directories)
23
+ \t\t\t * IMPORTANT: Always wrap patterns in double quotes ("") to avoid shell expansion.
24
+ \t\t\t Example) fosslight_source -e "dev/" "tests/"
23
25
  -o <output_path>\t Output path (Path or file name)
24
26
  -f <format>\t\t Output file formats
25
27
  \t\t\t ({', '.join(SUPPORT_FORMAT)})
@@ -19,10 +19,6 @@ from ._scan_item import is_package_dir
19
19
  from typing import Tuple
20
20
 
21
21
  logger = logging.getLogger(constant.LOGGER_NAME)
22
- _exclude_directory = ["test", "tests", "doc", "docs"]
23
- _exclude_directory = [os.path.sep + dir_name +
24
- os.path.sep for dir_name in _exclude_directory]
25
- _exclude_directory.append("/.")
26
22
  REMOVE_LICENSE = ["warranty-disclaimer"]
27
23
  regex = re.compile(r'licenseref-(\S+)', re.IGNORECASE)
28
24
  find_word = re.compile(rb"SPDX-PackageDownloadLocation\s*:\s*(\S+)", re.IGNORECASE)
@@ -108,7 +108,7 @@ class SourceItem(FileItem):
108
108
 
109
109
 
110
110
  def is_exclude_dir(dir_path: str) -> bool:
111
- if dir_path != "":
111
+ if dir_path:
112
112
  dir_path = dir_path.lower()
113
113
  dir_path = dir_path if dir_path.endswith(
114
114
  os.path.sep) else dir_path + os.path.sep
@@ -163,3 +163,21 @@ def is_package_dir(dir_path: str) -> bool:
163
163
  pkg_path = '/'.join(path_parts[:pkg_index + 1])
164
164
  return True, pkg_path
165
165
  return False, ""
166
+
167
+
168
+ def get_excluded_paths(path_to_scan: str, custom_excluded_paths: list = []) -> list:
169
+ path_to_exclude = custom_excluded_paths.copy()
170
+ abs_path_to_scan = os.path.abspath(path_to_scan)
171
+
172
+ for root, dirs, files in os.walk(path_to_scan):
173
+ for dir_name in dirs:
174
+ dir_path = os.path.join(root, dir_name)
175
+ rel_path = os.path.relpath(dir_path, abs_path_to_scan)
176
+ if dir_name in _package_directory:
177
+ if rel_path not in path_to_exclude:
178
+ path_to_exclude.append(rel_path)
179
+ elif is_exclude_dir(rel_path):
180
+ if rel_path not in path_to_exclude:
181
+ path_to_exclude.append(rel_path)
182
+
183
+ return path_to_exclude
fosslight_source/cli.py CHANGED
@@ -18,6 +18,7 @@ from ._license_matched import get_license_list_to_print
18
18
  from fosslight_util.output_format import check_output_formats_v2, write_output_file
19
19
  from fosslight_util.correct import correct_with_yaml
20
20
  from .run_scancode import run_scan
21
+ from ._scan_item import get_excluded_paths
21
22
  from .run_scanoss import run_scanoss_py
22
23
  from .run_scanoss import get_scanoss_extra_info
23
24
  import yaml
@@ -206,10 +207,8 @@ def create_report_file(
206
207
 
207
208
  scan_item = ScannerItem(PKG_NAME, _start_time)
208
209
  scan_item.set_cover_pathinfo(path_to_scan, path_to_exclude)
209
- files_count, removed_files_count = count_files(path_to_scan, path_to_exclude)
210
-
211
- scan_item.set_cover_comment(f"Total number of files : {files_count}")
212
- scan_item.set_cover_comment(f"Removed files : {removed_files_count}")
210
+ files_count, _ = count_files(path_to_scan, path_to_exclude)
211
+ scan_item.set_cover_comment(f"Scanned files: {files_count}")
213
212
 
214
213
  if api_limit_exceed:
215
214
  scan_item.set_cover_comment("(Some of) SCANOSS scan was skipped. (API limits being exceeded)")
@@ -347,16 +346,18 @@ def run_scanners(
347
346
  print_matched_text = False
348
347
 
349
348
  if success:
349
+ excluded_path_with_default_exclusion = get_excluded_paths(path_to_scan, path_to_exclude)
350
350
  if selected_scanner == 'scancode' or selected_scanner == 'all' or selected_scanner == '':
351
351
  success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(path_to_scan, output_file_name,
352
352
  write_json_file, num_cores, True,
353
353
  print_matched_text, formats, called_by_cli,
354
- time_out, correct_mode, correct_filepath)
354
+ time_out, correct_mode, correct_filepath,
355
+ excluded_path_with_default_exclusion)
355
356
  if selected_scanner == 'scanoss' or selected_scanner == 'all' or selected_scanner == '':
356
357
  scanoss_result, api_limit_exceed = run_scanoss_py(path_to_scan, output_file_name, formats, True, write_json_file,
357
- num_cores, path_to_exclude)
358
+ num_cores, excluded_path_with_default_exclusion)
358
359
  if selected_scanner in SCANNER_TYPE:
359
- spdx_downloads = get_spdx_downloads(path_to_scan, path_to_exclude)
360
+ spdx_downloads = get_spdx_downloads(path_to_scan, excluded_path_with_default_exclusion)
360
361
  merged_result = merge_results(scancode_result, scanoss_result, spdx_downloads)
361
362
  scan_item = create_report_file(start_time, merged_result, license_list, scanoss_result, selected_scanner,
362
363
  print_matched_text, output_path, output_files, output_extensions, correct_mode,
@@ -45,7 +45,6 @@ def run_scan(
45
45
 
46
46
  if not correct_filepath:
47
47
  correct_filepath = path_to_scan
48
-
49
48
  success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats)
50
49
  if success:
51
50
  if output_path == "": # if json output with _write_json_file not used, output_path won't be needed.
@@ -75,36 +74,66 @@ def run_scan(
75
74
  if os.path.isdir(path_to_scan):
76
75
  try:
77
76
  time_out = float(time_out)
77
+ logger.debug(f"Skipped by Scancode: {path_to_exclude}")
78
78
  pretty_params = {}
79
79
  pretty_params["path_to_scan"] = path_to_scan
80
80
  pretty_params["path_to_exclude"] = path_to_exclude
81
81
  pretty_params["output_file"] = output_file_name
82
82
  total_files_to_excluded = []
83
-
84
83
  if path_to_exclude:
85
- target_path = os.path.basename(path_to_scan) if os.path.isabs(path_to_scan) else path_to_scan
86
-
84
+ abs_path_to_scan = os.path.abspath(path_to_scan)
87
85
  for path in path_to_exclude:
88
- exclude_path = path
89
- isabs_exclude = os.path.isabs(path)
90
- if isabs_exclude:
91
- exclude_path = os.path.relpath(path, os.path.abspath(path_to_scan))
92
-
93
- exclude_path = os.path.join(target_path, exclude_path)
94
- if os.path.isdir(exclude_path):
95
- for root, _, files in os.walk(exclude_path):
96
- total_files_to_excluded.extend([os.path.normpath(os.path.join(root, file)).replace("\\", "/")
97
- for file in files])
98
- elif os.path.isfile(exclude_path):
99
- total_files_to_excluded.append(os.path.normpath(exclude_path).replace("\\", "/"))
100
-
86
+ if os.path.isabs(path):
87
+ exclude_path = os.path.relpath(path, abs_path_to_scan)
88
+ else:
89
+ exclude_path = path
90
+
91
+ exclude_path_normalized = os.path.normpath(exclude_path).replace("\\", "/")
92
+
93
+ if exclude_path_normalized.endswith("/**"):
94
+ exclude_path_normalized = exclude_path_normalized[:-3]
95
+ elif exclude_path_normalized.endswith("**"):
96
+ exclude_path_normalized = exclude_path_normalized.rstrip("*")
97
+
98
+ if exclude_path_normalized.startswith("**/"):
99
+ exclude_path_normalized = exclude_path_normalized[3:]
100
+
101
+ full_exclude_path = os.path.join(abs_path_to_scan, exclude_path)
102
+ is_dir = os.path.isdir(full_exclude_path)
103
+ is_file = os.path.isfile(full_exclude_path)
104
+ if is_dir:
105
+ dir_name = os.path.basename(exclude_path_normalized.rstrip("/"))
106
+ base_path = exclude_path_normalized.rstrip("/")
107
+
108
+ if dir_name:
109
+ total_files_to_excluded.append(dir_name)
110
+ max_depth = 0
111
+ for root, dirs, files in os.walk(full_exclude_path):
112
+ depth = root[len(full_exclude_path):].count(os.sep)
113
+ max_depth = max(max_depth, depth)
114
+ for depth in range(1, max_depth + 2):
115
+ pattern = base_path + "/*" * depth
116
+ total_files_to_excluded.append(pattern)
117
+ else:
118
+ total_files_to_excluded.append(exclude_path_normalized)
119
+ elif is_file:
120
+ total_files_to_excluded.append(exclude_path_normalized)
121
+ else:
122
+ if "/" in exclude_path_normalized:
123
+ dir_name = os.path.basename(exclude_path_normalized.rstrip("/"))
124
+ if dir_name:
125
+ total_files_to_excluded.append(dir_name)
126
+ total_files_to_excluded.append(exclude_path_normalized)
127
+
128
+ total_files_to_excluded = sorted(list(set(total_files_to_excluded)))
129
+ ignore_tuple = tuple(total_files_to_excluded)
101
130
  rc, results = cli.run_scan(path_to_scan, max_depth=100,
102
131
  strip_root=True, license=True,
103
132
  copyright=True, return_results=True,
104
133
  processes=num_cores, pretty_params=pretty_params,
105
134
  output_json_pp=output_json_file, only_findings=True,
106
135
  license_text=True, url=True, timeout=time_out,
107
- include=(), ignore=tuple(total_files_to_excluded))
136
+ include=(), ignore=ignore_tuple)
108
137
  if not rc:
109
138
  msg = "Source code analysis failed."
110
139
  success = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_source
3
- Version: 2.1.17
3
+ Version: 2.1.19
4
4
  Summary: FOSSLight Source Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_source_scanner
6
6
  Download-URL: https://github.com/fosslight/fosslight_source_scanner
@@ -17,7 +17,7 @@ License-File: LICENSE
17
17
  Requires-Dist: pyparsing
18
18
  Requires-Dist: scanoss>=1.18.0
19
19
  Requires-Dist: XlsxWriter
20
- Requires-Dist: fosslight_util>=2.1.30
20
+ Requires-Dist: fosslight_util>=2.1.31
21
21
  Requires-Dist: PyYAML
22
22
  Requires-Dist: wheel>=0.38.1
23
23
  Requires-Dist: intbitset
@@ -0,0 +1,16 @@
1
+ fosslight_source/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ fosslight_source/_help.py,sha256=QuoQvxBPV00IfuD2ft88uRQXMSdrL2rJB7CQr05w3Ng,2312
3
+ fosslight_source/_license_matched.py,sha256=-3H881XQjFDafRttBsuboS3VbCPYEvPH1pwWXptknE4,2164
4
+ fosslight_source/_parsing_scancode_file_item.py,sha256=VZf_-5f7DZi8Zkj9Bx9LETTxcW-9f0KyNQD_DVOUNes,20024
5
+ fosslight_source/_parsing_scanoss_file.py,sha256=0f5JzjnFU-kcPZRX7OKnextyvANjKwwNZeyCJVC7eME,4624
6
+ fosslight_source/_scan_item.py,sha256=5HWJ8j58snEjTqzYtKRB8RVfywVrzivkJQ6WMh7nBwA,7299
7
+ fosslight_source/cli.py,sha256=ApdTDaLEuH1LskLtcMrLyeRDIgIJUZlOp3RrWaju2Pc,16854
8
+ fosslight_source/run_scancode.py,sha256=h8HWoZr5R17kXCYjiR56ZTdpDwpFKPAurpUpjTvT424,9006
9
+ fosslight_source/run_scanoss.py,sha256=8wu3sa-YBqjfb5x2dbDJuAdw3rrExueOW23WdzqDCaU,5721
10
+ fosslight_source/run_spdx_extractor.py,sha256=Hr9sTv06cJaVITy8amwexIW2FV8_rUcFw6hKmR9ZYws,1990
11
+ fosslight_source-2.1.19.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ fosslight_source-2.1.19.dist-info/METADATA,sha256=E_y220fkjF5KUrZUglR9MscDfD9AnBX5h63kO1FkAOg,3558
13
+ fosslight_source-2.1.19.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
14
+ fosslight_source-2.1.19.dist-info/entry_points.txt,sha256=G4bBRWqSrJ68g-2M-JtNDrSZsdym_M7_KohQ2qR1vG8,113
15
+ fosslight_source-2.1.19.dist-info/top_level.txt,sha256=C2vw-0OIent84Vq-UEk1gt_kK1EL8dIItzBzp3WNyA4,17
16
+ fosslight_source-2.1.19.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- fosslight_source/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_source/_help.py,sha256=UEfOI6Jx38cDLN4CZ8TTk3u8TL2r0aG2V9IZKa-l3aI,2138
3
- fosslight_source/_license_matched.py,sha256=-3H881XQjFDafRttBsuboS3VbCPYEvPH1pwWXptknE4,2164
4
- fosslight_source/_parsing_scancode_file_item.py,sha256=DA2tEbjCHXFLfavCh0TjRIF1-dE4Ep7X2ivDF8IJqS8,20227
5
- fosslight_source/_parsing_scanoss_file.py,sha256=0f5JzjnFU-kcPZRX7OKnextyvANjKwwNZeyCJVC7eME,4624
6
- fosslight_source/_scan_item.py,sha256=9bm1kOeBudIb2M8wmmRKAzOFdkdBTUtoyO2LQKaJeDQ,6584
7
- fosslight_source/cli.py,sha256=2TuHZvDKUp8R12DM9gesTF23RT7OBw968AdzNLtVanU,16650
8
- fosslight_source/run_scancode.py,sha256=YSzLoS4p-Kge91uQpI4483ZfiapF-3umgJHggxKtiuU,7220
9
- fosslight_source/run_scanoss.py,sha256=8wu3sa-YBqjfb5x2dbDJuAdw3rrExueOW23WdzqDCaU,5721
10
- fosslight_source/run_spdx_extractor.py,sha256=Hr9sTv06cJaVITy8amwexIW2FV8_rUcFw6hKmR9ZYws,1990
11
- fosslight_source-2.1.17.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- fosslight_source-2.1.17.dist-info/METADATA,sha256=8vCF2Vq_rTqWgf9DOizhRBPyhNhVsS9S6GLT9RtbtPw,3558
13
- fosslight_source-2.1.17.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
14
- fosslight_source-2.1.17.dist-info/entry_points.txt,sha256=G4bBRWqSrJ68g-2M-JtNDrSZsdym_M7_KohQ2qR1vG8,113
15
- fosslight_source-2.1.17.dist-info/top_level.txt,sha256=C2vw-0OIent84Vq-UEk1gt_kK1EL8dIItzBzp3WNyA4,17
16
- fosslight_source-2.1.17.dist-info/RECORD,,