scanoss 1.25.0__py3-none-any.whl → 1.25.2__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.
scanoss/__init__.py CHANGED
@@ -22,4 +22,4 @@ SPDX-License-Identifier: MIT
22
22
  THE SOFTWARE.
23
23
  """
24
24
 
25
- __version__ = '1.25.0'
25
+ __version__ = '1.25.2'
@@ -1 +1 @@
1
- date: 20250610161304, utime: 1749571984
1
+ date: 20250618150502, utime: 1750259102
@@ -23,7 +23,8 @@ SPDX-License-Identifier: MIT
23
23
  """
24
24
 
25
25
  import json
26
- from typing import Dict, Any
26
+ from typing import Any, Dict
27
+
27
28
  from .policy_check import PolicyCheck, PolicyStatus
28
29
 
29
30
 
@@ -33,7 +34,7 @@ class Copyleft(PolicyCheck):
33
34
  Inspects components for copyleft licenses
34
35
  """
35
36
 
36
- def __init__(
37
+ def __init__( # noqa: PLR0913
37
38
  self,
38
39
  debug: bool = False,
39
40
  trace: bool = True,
@@ -158,6 +159,26 @@ class Copyleft(PolicyCheck):
158
159
  self.print_debug(f'Copyleft components: {filtered_components}')
159
160
  return filtered_components
160
161
 
162
+ def _get_components(self):
163
+ """
164
+ Extract and process components from results and their dependencies.
165
+
166
+ This method performs the following steps:
167
+ 1. Validates that `self.results` is loaded. Returns `None` if not.
168
+ 2. Extracts file, snippet, and dependency components into a dictionary.
169
+ 3. Converts components to a list and processes their licenses.
170
+
171
+ :return: A list of processed components with license data, or `None` if `self.results` is not set.
172
+ """
173
+ if self.results is None:
174
+ return None
175
+
176
+ components: dict = {}
177
+ # Extract component and license data from file and dependency results. Both helpers mutate `components`
178
+ self._get_components_data(self.results, components)
179
+ self._get_dependencies_data(self.results, components)
180
+ return self._convert_components_to_list(components)
181
+
161
182
  def run(self):
162
183
  """
163
184
  Run the copyleft license inspection process.
@@ -166,6 +166,30 @@ class PolicyCheck(ScanossBase):
166
166
  """
167
167
  pass
168
168
 
169
+ @abstractmethod
170
+ def _get_components(self):
171
+ """
172
+ Retrieve and process components from the preloaded results.
173
+
174
+ This method performs the following steps:
175
+ 1. Checks if the results have been previously loaded (self.results).
176
+ 2. Extracts and processes components from the loaded results.
177
+
178
+ :return: A list of processed components, or None if an error occurred during any step.
179
+
180
+ Possible reasons for returning None include:
181
+ - Results not loaded (self.results is None)
182
+ - Failure to extract components from the results
183
+
184
+ Note:
185
+ - This method assumes that the results have been previously loaded and stored in self.results.
186
+ - Implementations must extract components (e.g. via `_get_components_data`,
187
+ `_get_dependencies_data`, or other helpers).
188
+ - If `self.results` is `None`, simply return `None`.
189
+ """
190
+ pass
191
+
192
+
169
193
  def _append_component(
170
194
  self, components: Dict[str, Any], new_component: Dict[str, Any], id: str, status: str
171
195
  ) -> Dict[str, Any]:
@@ -188,6 +212,10 @@ class PolicyCheck(ScanossBase):
188
212
  else:
189
213
  purl = new_component['purl']
190
214
 
215
+ if not purl:
216
+ self.print_debug(f'WARNING: _append_component: No purl found for new component: {new_component}')
217
+ return components
218
+
191
219
  component_key = f'{purl}@{new_component["version"]}'
192
220
  components[component_key] = {
193
221
  'purl': purl,
@@ -198,14 +226,21 @@ class PolicyCheck(ScanossBase):
198
226
  if not new_component.get('licenses'):
199
227
  self.print_debug(f'WARNING: Results missing licenses. Skipping: {new_component}')
200
228
  return components
229
+
230
+
231
+ licenses_order_by_source_priority = self._get_licenses_order_by_source_priority(new_component['licenses'])
201
232
  # Process licenses for this component
202
- for license_item in new_component['licenses']:
233
+ for license_item in licenses_order_by_source_priority:
203
234
  if license_item.get('name'):
204
235
  spdxid = license_item['name']
236
+ source = license_item.get('source')
237
+ if not source:
238
+ source = 'unknown'
205
239
  components[component_key]['licenses'][spdxid] = {
206
240
  'spdxid': spdxid,
207
241
  'copyleft': self.license_util.is_copyleft(spdxid),
208
242
  'url': self.license_util.get_spdx_url(spdxid),
243
+ 'source': source,
209
244
  }
210
245
  return components
211
246
 
@@ -223,6 +258,9 @@ class PolicyCheck(ScanossBase):
223
258
  if not component_id:
224
259
  self.print_debug(f'WARNING: Result missing id. Skipping: {c}')
225
260
  continue
261
+ ## Skip dependency
262
+ if component_id == ComponentID.DEPENDENCY.value:
263
+ continue
226
264
  status = c.get('status')
227
265
  if not status:
228
266
  self.print_debug(f'WARNING: Result missing status. Skipping: {c}')
@@ -234,10 +272,12 @@ class PolicyCheck(ScanossBase):
234
272
  if len(c.get('purl')) <= 0:
235
273
  self.print_debug(f'WARNING: Result missing purls. Skipping: {c}')
236
274
  continue
237
- if not c.get('version'):
238
- self.print_msg(f'WARNING: Result missing version. Skipping: {c}')
239
- continue
240
- component_key = f'{c["purl"][0]}@{c["version"]}'
275
+ version = c.get('version')
276
+ if not version:
277
+ self.print_debug(f'WARNING: Result missing version. Setting it to unknown: {c}')
278
+ version = 'unknown'
279
+ c['version'] = version #If no version exists. Set 'unknown' version to current component
280
+ component_key = f'{c["purl"][0]}@{version}'
241
281
  if component_key not in components:
242
282
  components = self._append_component(components, c, component_id, status)
243
283
  # End component loop
@@ -269,10 +309,12 @@ class PolicyCheck(ScanossBase):
269
309
  if not dependency.get('purl'):
270
310
  self.print_debug(f'WARNING: Dependency result missing purl. Skipping: {dependency}')
271
311
  continue
272
- if not dependency.get('version'):
273
- self.print_msg(f'WARNING: Dependency result missing version. Skipping: {dependency}')
274
- continue
275
- component_key = f'{dependency["purl"]}@{dependency["version"]}'
312
+ version = c.get('version')
313
+ if not version:
314
+ self.print_debug(f'WARNING: Result missing version. Setting it to unknown: {c}')
315
+ version = 'unknown'
316
+ c['version'] = version # If no version exists. Set 'unknown' version to current component
317
+ component_key = f'{dependency["purl"]}@{version}'
276
318
  if component_key not in components:
277
319
  components = self._append_component(components, dependency, component_id, status)
278
320
  # End dependency loop
@@ -280,33 +322,6 @@ class PolicyCheck(ScanossBase):
280
322
  # End of result loop
281
323
  return components
282
324
 
283
- def _get_components_from_results(self, results: Dict[str, Any]) -> list or None:
284
- """
285
- Process the results dictionary to extract and format component information.
286
-
287
- This function iterates through the results dictionary, identifying components from
288
- different sources (files, snippets, and dependencies). It consolidates this information
289
- into a list of unique components, each with its associated licenses and other details.
290
-
291
- :param results: A dictionary containing the raw results of a component scan
292
- :return: A list of dictionaries, each representing a unique component with its details
293
- """
294
- if results is None:
295
- self.print_stderr('ERROR: Results cannot be empty')
296
- return None
297
-
298
- components = {}
299
- # Extract file and snippet components
300
- components = self._get_components_data(results, components)
301
- # Extract dependency components
302
- components = self._get_dependencies_data(results, components)
303
- # Convert to list and process licenses
304
- results_list = list(components.values())
305
- for component in results_list:
306
- component['licenses'] = list(component['licenses'].values())
307
-
308
- return results_list
309
-
310
325
  def generate_table(self, headers, rows, centered_columns=None):
311
326
  """
312
327
  Generate a Markdown table.
@@ -411,28 +426,60 @@ class PolicyCheck(ScanossBase):
411
426
  self.print_stderr(f'ERROR: Problem parsing input JSON: {e}')
412
427
  return None
413
428
 
414
- def _get_components(self):
415
- """
416
- Retrieve and process components from the preloaded results.
429
+ def _convert_components_to_list(self, components: dict):
430
+ if components is None:
431
+ self.print_debug(f'WARNING: Components is empty {self.results}')
432
+ return None
433
+ results_list = list(components.values())
434
+ for component in results_list:
435
+ licenses = component.get('licenses')
436
+ if licenses is not None:
437
+ component['licenses'] = list(licenses.values())
438
+ else:
439
+ self.print_debug(f'WARNING: Licenses missing for: {component}')
440
+ component['licenses'] = []
441
+ return results_list
417
442
 
418
- This method performs the following steps:
419
- 1. Checks if the results have been previously loaded (self.results).
420
- 2. Extracts and processes components from the loaded results.
443
+ def _get_licenses_order_by_source_priority(self,licenses_data):
444
+ """
445
+ Select licenses based on source priority:
446
+ 1. component_declared (highest priority)
447
+ 2. license_file
448
+ 3. file_header
449
+ 4. scancode (lowest priority)
421
450
 
422
- :return: A list of processed components, or None if an error occurred during any step.
423
- Possible reasons for returning None include:
424
- - Results not loaded (self.results is None)
425
- - Failure to extract components from the results
451
+ If any high-priority source is found, return only licenses from that source.
452
+ If none found, return all licenses.
426
453
 
427
- Note:
428
- - This method assumes that the results have been previously loaded and stored in self.results.
429
- - If results is None, the method returns None without performing any further operations.
430
- - The actual processing of components is delegated to the _get_components_from_results method.
454
+ Returns: list with ordered licenses by source.
431
455
  """
432
- if self.results is None:
433
- return None
434
- components = self._get_components_from_results(self.results)
435
- return components
456
+ # Define priority order (highest to lowest)
457
+ priority_sources = ['component_declared', 'license_file', 'file_header', 'scancode']
458
+
459
+ # Group licenses by source
460
+ licenses_by_source = {}
461
+ for license_item in licenses_data:
462
+
463
+ source = license_item.get('source', 'unknown')
464
+ if source not in licenses_by_source:
465
+ licenses_by_source[source] = {}
466
+
467
+ license_name = license_item.get('name')
468
+ if license_name:
469
+ # Use license name as key, store full license object as value
470
+ # If duplicate license names exist in same source, the last one wins
471
+ licenses_by_source[source][license_name] = license_item
472
+
473
+ # Find the highest priority source that has licenses
474
+ for priority_source in priority_sources:
475
+ if priority_source in licenses_by_source:
476
+ self.print_trace(f'Choosing {priority_source} as source')
477
+ return list(licenses_by_source[priority_source].values())
478
+
479
+ # If no priority sources found, combine all licenses into a single list
480
+ self.print_debug("No priority sources found, returning all licenses as list")
481
+ return licenses_data
482
+
436
483
 
437
484
  #
438
485
  # End of PolicyCheck Class
@@ -23,7 +23,8 @@ SPDX-License-Identifier: MIT
23
23
  """
24
24
 
25
25
  import json
26
- from typing import Dict, Any
26
+ from typing import Any, Dict
27
+
27
28
  from .policy_check import PolicyCheck, PolicyStatus
28
29
 
29
30
 
@@ -33,7 +34,7 @@ class UndeclaredComponent(PolicyCheck):
33
34
  Inspects for undeclared components
34
35
  """
35
36
 
36
- def __init__(
37
+ def __init__( # noqa: PLR0913
37
38
  self,
38
39
  debug: bool = False,
39
40
  trace: bool = True,
@@ -73,7 +74,7 @@ class UndeclaredComponent(PolicyCheck):
73
74
  :return: List of undeclared components
74
75
  """
75
76
  if components is None:
76
- self.print_debug(f'WARNING: No components provided!')
77
+ self.print_debug('WARNING: No components provided!')
77
78
  return None
78
79
  undeclared_components = []
79
80
  for component in components:
@@ -87,25 +88,35 @@ class UndeclaredComponent(PolicyCheck):
87
88
  """
88
89
  Get a summary of the undeclared components.
89
90
 
91
+ :param components: List of all components
92
+ :return: Component summary markdown
93
+ """
94
+
95
+ """
96
+ Get a summary of the undeclared components.
97
+
90
98
  :param components: List of all components
91
99
  :return: Component summary markdown
92
100
  """
93
101
  if len(components) > 0:
102
+ json_content = json.dumps(self._generate_scanoss_file(components), indent=2)
103
+
94
104
  if self.sbom_format == 'settings':
95
- json_str = (
96
- json.dumps(self._generate_scanoss_file(components), indent=2)
97
- .replace('\n', '\\n')
98
- .replace('"', '\\"')
105
+ return (
106
+ f'{len(components)} undeclared component(s) were found.\n'
107
+ f'Add the following snippet into your `scanoss.json` file\n'
108
+ f'{{code:json}}\n'
109
+ f'{json_content}\n'
110
+ f'{{code}}\n'
99
111
  )
100
- return f'{len(components)} undeclared component(s) were found.\nAdd the following snippet into your `scanoss.json` file\n{{code:json}}\n{json.dumps(self._generate_scanoss_file(components), indent=2)}\n{{code}}\n'
101
112
  else:
102
- json_str = (
103
- json.dumps(self._generate_scanoss_file(components), indent=2)
104
- .replace('\n', '\\n')
105
- .replace('"', '\\"')
113
+ return (
114
+ f'{len(components)} undeclared component(s) were found.\n'
115
+ f'Add the following snippet into your `sbom.json` file\n'
116
+ f'{{code:json}}\n'
117
+ f'{json_content}\n'
118
+ f'{{code}}\n'
106
119
  )
107
- return f'{len(components)} undeclared component(s) were found.\nAdd the following snippet into your `sbom.json` file\n{{code:json}}\n{json.dumps(self._generate_scanoss_file(components), indent=2)}\n{{code}}\n'
108
-
109
120
  return f'{len(components)} undeclared component(s) were found.\\n'
110
121
 
111
122
  def _get_summary(self, components: list) -> str:
@@ -190,7 +201,7 @@ class UndeclaredComponent(PolicyCheck):
190
201
  """
191
202
  unique_components = {}
192
203
  if components is None:
193
- self.print_stderr(f'WARNING: No components provided!')
204
+ self.print_stderr('WARNING: No components provided!')
194
205
  return []
195
206
 
196
207
  for component in components:
@@ -225,6 +236,26 @@ class UndeclaredComponent(PolicyCheck):
225
236
 
226
237
  return sbom
227
238
 
239
+ def _get_components(self):
240
+ """
241
+ Extract and process components from file results only.
242
+
243
+ This method performs the following steps:
244
+ 1. Validates if `self.results` is loaded. Returns `None` if not loaded.
245
+ 2. Extracts file and snippet components into a dictionary.
246
+ 3. Converts the components dictionary into a list of components.
247
+ 4. Processes the licenses for each component by converting them into a list.
248
+
249
+ :return: A list of processed components with their licenses, or `None` if `self.results` is not set.
250
+ """
251
+ if self.results is None:
252
+ return None
253
+ components: dict = {}
254
+ # Extract file and snippet components
255
+ components = self._get_components_data(self.results, components)
256
+ # Convert to list and process licenses
257
+ return self._convert_components_to_list(components)
258
+
228
259
  def run(self):
229
260
  """
230
261
  Run the undeclared component inspection process.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scanoss
3
- Version: 1.25.0
3
+ Version: 1.25.2
4
4
  Summary: Simple Python library to leverage the SCANOSS APIs
5
5
  Home-page: https://scanoss.com
6
6
  Author: SCANOSS
@@ -4,7 +4,7 @@ protoc_gen_swagger/options/annotations_pb2.py,sha256=b25EDD6gssUWnFby9gxgcpLIROT
4
4
  protoc_gen_swagger/options/annotations_pb2_grpc.py,sha256=1oboBPFxaTEXt9Aw7EAj8gXHDCNMhZD2VXqocC9l_gk,159
5
5
  protoc_gen_swagger/options/openapiv2_pb2.py,sha256=vYElGp8E1vGHszvWqX97zNG9GFJ7u2QcdK9ouq0XdyI,14939
6
6
  protoc_gen_swagger/options/openapiv2_pb2_grpc.py,sha256=1oboBPFxaTEXt9Aw7EAj8gXHDCNMhZD2VXqocC9l_gk,159
7
- scanoss/__init__.py,sha256=T3J1XVw8Hyutct8ClOLn1tqQ_NnHlMfxUSVYfLSuVJg,1146
7
+ scanoss/__init__.py,sha256=9K1SKldg4taEpZ7t4H-Z45hI8SIqMlSmjp6TFz3Km2w,1146
8
8
  scanoss/cli.py,sha256=SAB0xuHjEEw20YtYAPSZwrQaVf4JUsm8NRcVArMzd4U,69099
9
9
  scanoss/components.py,sha256=b0R9DdKuXqyQiw5nZZwjQ6NJXBr1U9gyx1RI2FP9ozA,14511
10
10
  scanoss/constants.py,sha256=FWCZG8gQputKwV7XwvW1GuwDXL4wDLQyVRGdwygg578,320
@@ -57,14 +57,14 @@ scanoss/api/vulnerabilities/__init__.py,sha256=IFrDk_DTJgKSZmmU-nuLXuq_s8sQZlrSC
57
57
  scanoss/api/vulnerabilities/v2/__init__.py,sha256=IFrDk_DTJgKSZmmU-nuLXuq_s8sQZlrSCHhIDMJT4r0,1122
58
58
  scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2.py,sha256=CFhF80av8tenGvn9AIsGEtRJPuV2dC_syA5JLZb2lDw,5464
59
59
  scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2_grpc.py,sha256=HlS4k4Zmx6RIAqaO9I96jD-eyF5yU6Xx04pVm7pdqOg,6864
60
- scanoss/data/build_date.txt,sha256=3dG3QmOR7re5yDaUAaCa2noLbeaUxqlhd4ZYGn2-eo0,40
60
+ scanoss/data/build_date.txt,sha256=3-u7TU-KPaW2lJLuHTSTYQJlq8aqKlVQv7MRd_B-xvQ,40
61
61
  scanoss/data/scanoss-settings-schema.json,sha256=ClkRYAkjAN0Sk704G8BE_Ok006oQ6YnIGmX84CF8h9w,8798
62
62
  scanoss/data/spdx-exceptions.json,sha256=s7UTYxC7jqQXr11YBlIWYCNwN6lRDFTR33Y8rpN_dA4,17953
63
63
  scanoss/data/spdx-licenses.json,sha256=A6Z0q82gaTLtnopBfzeIVZjJFxkdRW1g2TuumQc-lII,228794
64
64
  scanoss/inspection/__init__.py,sha256=0hjb5ktavp7utJzFhGMPImPaZiHWgilM2HwvTp5lXJE,1122
65
- scanoss/inspection/copyleft.py,sha256=VynluuCUVxR7uQUz026sp4_yE0Eh3dwpPK0YJ6FNFFw,7579
66
- scanoss/inspection/policy_check.py,sha256=wUUQD2WTBibjf3MOPXKOmB8jFGIX0cd1K3flU0pjTjc,17295
67
- scanoss/inspection/undeclared_component.py,sha256=0YEiWQ4Q1xu7j4YHLPsS3b5Mf9fplHJdHRXgUoQyF2w,10102
65
+ scanoss/inspection/copyleft.py,sha256=MqkixiGnOs7IEfhSmX5zRkJmmouHc76q8LP2Rqdu4AQ,8495
66
+ scanoss/inspection/policy_check.py,sha256=k8v7ei3oZBERt4l8S3AWEVn-qA2TsGkfYJT_i21M0s4,19076
67
+ scanoss/inspection/undeclared_component.py,sha256=my-KPEeFx7P2VG2dsYm5-7y83DDMGzf0MnBQdPExIHk,11026
68
68
  scanoss/inspection/utils/license_utils.py,sha256=Zb6QLmVJb86lKCwZyBsmwakyAtY1SXa54kUyyKmWMqA,5093
69
69
  scanoss/scanners/__init__.py,sha256=D4C0lWLuNp8k_BjQZEc07WZcUgAvriVwQWOk063b0ZU,1122
70
70
  scanoss/scanners/container_scanner.py,sha256=leP4roes6B9B95F49mJ0P_F8WcKCQkvJgk9azWyJrjg,16294
@@ -76,9 +76,9 @@ scanoss/utils/abstract_presenter.py,sha256=teiDTxBj5jBMCk2T8i4l1BJPf_u4zBLWrtCTF
76
76
  scanoss/utils/crc64.py,sha256=TMrwQimSdE6imhFOUL7oAG6Kxu-8qMpGWMuMg8QpSVs,3169
77
77
  scanoss/utils/file.py,sha256=62cA9a17TU9ZvfA3FY5HY4-QOajJeSrc8S6xLA_f-3M,2980
78
78
  scanoss/utils/simhash.py,sha256=6iu8DOcecPAY36SZjCOzrrLMT9oIE7-gI6QuYwUQ7B0,5793
79
- scanoss-1.25.0.dist-info/licenses/LICENSE,sha256=LLUaXoiyOroIbr5ubAyrxBOwSRLTm35ETO2FmLpy8QQ,1074
80
- scanoss-1.25.0.dist-info/METADATA,sha256=mvajvjxQSlBpII6nFUq44pp7-Kedgf9hXGblfCjqjWU,6060
81
- scanoss-1.25.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
- scanoss-1.25.0.dist-info/entry_points.txt,sha256=Uy28xnaDL5KQ7V77sZD5VLDXPNxYYzSr5tsqtiXVzAs,48
83
- scanoss-1.25.0.dist-info/top_level.txt,sha256=V11PrQ6Pnrc-nDF9xnisnJ8e6-i7HqSIKVNqduRWcL8,27
84
- scanoss-1.25.0.dist-info/RECORD,,
79
+ scanoss-1.25.2.dist-info/licenses/LICENSE,sha256=LLUaXoiyOroIbr5ubAyrxBOwSRLTm35ETO2FmLpy8QQ,1074
80
+ scanoss-1.25.2.dist-info/METADATA,sha256=tLuNgHCCKBeUfqk0EWRkr5iv35GBIybi0nMBSBi1huw,6060
81
+ scanoss-1.25.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
+ scanoss-1.25.2.dist-info/entry_points.txt,sha256=Uy28xnaDL5KQ7V77sZD5VLDXPNxYYzSr5tsqtiXVzAs,48
83
+ scanoss-1.25.2.dist-info/top_level.txt,sha256=V11PrQ6Pnrc-nDF9xnisnJ8e6-i7HqSIKVNqduRWcL8,27
84
+ scanoss-1.25.2.dist-info/RECORD,,