scanoss 1.19.6__py3-none-any.whl → 1.20.1__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.
Files changed (71) hide show
  1. protoc_gen_swagger/__init__.py +13 -13
  2. protoc_gen_swagger/options/__init__.py +13 -13
  3. protoc_gen_swagger/options/annotations_pb2.py +12 -9
  4. protoc_gen_swagger/options/annotations_pb2_grpc.py +1 -1
  5. protoc_gen_swagger/options/openapiv2_pb2.py +98 -96
  6. protoc_gen_swagger/options/openapiv2_pb2_grpc.py +1 -1
  7. scanoss/__init__.py +18 -18
  8. scanoss/api/__init__.py +17 -17
  9. scanoss/api/common/__init__.py +17 -17
  10. scanoss/api/common/v2/__init__.py +17 -17
  11. scanoss/api/common/v2/scanoss_common_pb2.py +18 -18
  12. scanoss/api/common/v2/scanoss_common_pb2_grpc.py +1 -1
  13. scanoss/api/components/__init__.py +17 -17
  14. scanoss/api/components/v2/__init__.py +17 -17
  15. scanoss/api/components/v2/scanoss_components_pb2.py +48 -38
  16. scanoss/api/components/v2/scanoss_components_pb2_grpc.py +142 -96
  17. scanoss/api/cryptography/v2/scanoss_cryptography_pb2.py +22 -16
  18. scanoss/api/cryptography/v2/scanoss_cryptography_pb2_grpc.py +75 -49
  19. scanoss/api/dependencies/__init__.py +17 -17
  20. scanoss/api/dependencies/v2/__init__.py +17 -17
  21. scanoss/api/dependencies/v2/scanoss_dependencies_pb2.py +30 -24
  22. scanoss/api/dependencies/v2/scanoss_dependencies_pb2_grpc.py +75 -49
  23. scanoss/api/provenance/__init__.py +23 -0
  24. scanoss/api/provenance/v2/__init__.py +23 -0
  25. scanoss/api/provenance/v2/scanoss_provenance_pb2.py +42 -0
  26. scanoss/api/provenance/v2/scanoss_provenance_pb2_grpc.py +108 -0
  27. scanoss/api/scanning/__init__.py +17 -17
  28. scanoss/api/scanning/v2/__init__.py +17 -17
  29. scanoss/api/scanning/v2/scanoss_scanning_pb2.py +10 -8
  30. scanoss/api/scanning/v2/scanoss_scanning_pb2_grpc.py +40 -32
  31. scanoss/api/semgrep/__init__.py +17 -17
  32. scanoss/api/semgrep/v2/__init__.py +17 -17
  33. scanoss/api/semgrep/v2/scanoss_semgrep_pb2.py +22 -18
  34. scanoss/api/semgrep/v2/scanoss_semgrep_pb2_grpc.py +71 -49
  35. scanoss/api/vulnerabilities/__init__.py +17 -17
  36. scanoss/api/vulnerabilities/v2/__init__.py +17 -17
  37. scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2.py +37 -27
  38. scanoss/api/vulnerabilities/v2/scanoss_vulnerabilities_pb2_grpc.py +109 -72
  39. scanoss/cli.py +578 -264
  40. scanoss/components.py +99 -48
  41. scanoss/csvoutput.py +83 -56
  42. scanoss/cyclonedx.py +48 -46
  43. scanoss/data/build_date.txt +1 -1
  44. scanoss/file_filters.py +13 -15
  45. scanoss/filecount.py +43 -36
  46. scanoss/inspection/__init__.py +17 -17
  47. scanoss/inspection/copyleft.py +71 -58
  48. scanoss/inspection/policy_check.py +76 -53
  49. scanoss/inspection/undeclared_component.py +98 -75
  50. scanoss/inspection/utils/license_utils.py +66 -44
  51. scanoss/results.py +51 -60
  52. scanoss/scancodedeps.py +61 -38
  53. scanoss/scanner.py +203 -135
  54. scanoss/scanoss_settings.py +5 -3
  55. scanoss/scanossapi.py +98 -69
  56. scanoss/scanossbase.py +19 -19
  57. scanoss/scanossgrpc.py +107 -51
  58. scanoss/scanpostprocessor.py +9 -6
  59. scanoss/scantype.py +22 -21
  60. scanoss/spdxlite.py +265 -171
  61. scanoss/threadeddependencies.py +91 -61
  62. scanoss/threadedscanning.py +37 -31
  63. scanoss/utils/file.py +4 -4
  64. scanoss/winnowing.py +111 -47
  65. {scanoss-1.19.6.dist-info → scanoss-1.20.1.dist-info}/METADATA +1 -1
  66. scanoss-1.20.1.dist-info/RECORD +74 -0
  67. scanoss-1.19.6.dist-info/RECORD +0 -70
  68. {scanoss-1.19.6.dist-info → scanoss-1.20.1.dist-info}/LICENSE +0 -0
  69. {scanoss-1.19.6.dist-info → scanoss-1.20.1.dist-info}/WHEEL +0 -0
  70. {scanoss-1.19.6.dist-info → scanoss-1.20.1.dist-info}/entry_points.txt +0 -0
  71. {scanoss-1.19.6.dist-info → scanoss-1.20.1.dist-info}/top_level.txt +0 -0
@@ -1,61 +1,82 @@
1
1
  """
2
- SPDX-License-Identifier: MIT
3
-
4
- Copyright (c) 2024, SCANOSS
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2024, SCANOSS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
23
  """
24
+
24
25
  from ...scanossbase import ScanossBase
25
26
 
26
27
  DEFAULT_COPYLEFT_LICENSES = {
27
- 'agpl-3.0-only', 'artistic-1.0', 'artistic-2.0', 'cc-by-sa-4.0', 'cddl-1.0', 'cddl-1.1', 'cecill-2.1',
28
- 'epl-1.0', 'epl-2.0', 'gfdl-1.1-only', 'gfdl-1.2-only', 'gfdl-1.3-only', 'gpl-1.0-only', 'gpl-2.0-only',
29
- 'gpl-3.0-only', 'lgpl-2.1-only', 'lgpl-3.0-only', 'mpl-1.1', 'mpl-2.0', 'sleepycat', 'watcom-1.0'
28
+ 'agpl-3.0-only',
29
+ 'artistic-1.0',
30
+ 'artistic-2.0',
31
+ 'cc-by-sa-4.0',
32
+ 'cddl-1.0',
33
+ 'cddl-1.1',
34
+ 'cecill-2.1',
35
+ 'epl-1.0',
36
+ 'epl-2.0',
37
+ 'gfdl-1.1-only',
38
+ 'gfdl-1.2-only',
39
+ 'gfdl-1.3-only',
40
+ 'gpl-1.0-only',
41
+ 'gpl-2.0-only',
42
+ 'gpl-3.0-only',
43
+ 'lgpl-2.1-only',
44
+ 'lgpl-3.0-only',
45
+ 'mpl-1.1',
46
+ 'mpl-2.0',
47
+ 'sleepycat',
48
+ 'watcom-1.0',
30
49
  }
31
50
 
51
+
32
52
  class LicenseUtil(ScanossBase):
33
53
  """
34
- A utility class for handling software licenses, particularly copyleft licenses.
54
+ A utility class for handling software licenses, particularly copyleft licenses.
35
55
 
36
- This class provides functionality to initialize, manage, and query a set of
37
- copyleft licenses. It also offers a method to generate URLs for license information.
56
+ This class provides functionality to initialize, manage, and query a set of
57
+ copyleft licenses. It also offers a method to generate URLs for license information.
38
58
  """
59
+
39
60
  BASE_SPDX_ORG_URL = 'https://spdx.org/licenses'
40
61
  BASE_OSADL_URL = 'https://www.osadl.org/fileadmin/checklists/unreflicenses'
41
62
 
42
- def __init__(self,debug: bool = False, trace: bool = True, quiet: bool = False):
63
+ def __init__(self, debug: bool = False, trace: bool = True, quiet: bool = False):
43
64
  super().__init__(debug, trace, quiet)
44
65
  self.default_copyleft_licenses = set(DEFAULT_COPYLEFT_LICENSES)
45
66
  self.copyleft_licenses = set()
46
67
 
47
68
  def init(self, include: str = None, exclude: str = None, explicit: str = None):
48
69
  """
49
- Initialize the set of copyleft licenses based on user input.
70
+ Initialize the set of copyleft licenses based on user input.
50
71
 
51
- This method allows for customization of the copyleft license set by:
52
- - Setting an explicit list of licenses
53
- - Including additional licenses to the default set
54
- - Excluding specific licenses from the default set
72
+ This method allows for customization of the copyleft license set by:
73
+ - Setting an explicit list of licenses
74
+ - Including additional licenses to the default set
75
+ - Excluding specific licenses from the default set
55
76
 
56
- :param include: Comma-separated string of licenses to include
57
- :param exclude: Comma-separated string of licenses to exclude
58
- :param explicit: Comma-separated string of licenses to use exclusively
77
+ :param include: Comma-separated string of licenses to include
78
+ :param exclude: Comma-separated string of licenses to exclude
79
+ :param explicit: Comma-separated string of licenses to use exclusively
59
80
  """
60
81
  if self.debug:
61
82
  self.print_stderr(f'Include Copyleft licenses: ${include}')
@@ -73,7 +94,7 @@ class LicenseUtil(ScanossBase):
73
94
  if include:
74
95
  include = include.strip()
75
96
  if include:
76
- inc =[item.strip().lower() for item in include.split(',')]
97
+ inc = [item.strip().lower() for item in include.split(',')]
77
98
  self.copyleft_licenses.update(inc)
78
99
  if exclude:
79
100
  exclude = exclude.strip()
@@ -85,23 +106,22 @@ class LicenseUtil(ScanossBase):
85
106
 
86
107
  def is_copyleft(self, spdxid: str) -> bool:
87
108
  """
88
- Check if a given license is considered copyleft.
109
+ Check if a given license is considered copyleft.
89
110
 
90
- :param spdxid: The SPDX identifier of the license to check
91
- :return: True if the license is copyleft, False otherwise
111
+ :param spdxid: The SPDX identifier of the license to check
112
+ :return: True if the license is copyleft, False otherwise
92
113
  """
93
114
  return spdxid.lower() in self.copyleft_licenses
94
115
 
95
116
  def get_spdx_url(self, spdxid: str) -> str:
96
117
  """
97
- Generate the URL for the SPDX page of a license.
118
+ Generate the URL for the SPDX page of a license.
98
119
 
99
- :param spdxid: The SPDX identifier of the license
100
- :return: The URL of the SPDX page for the given license
120
+ :param spdxid: The SPDX identifier of the license
121
+ :return: The URL of the SPDX page for the given license
101
122
  """
102
123
  return f'{self.BASE_SPDX_ORG_URL}/{spdxid}.html'
103
124
 
104
-
105
125
  def get_osadl_url(self, spdxid: str) -> str:
106
126
  """
107
127
  Generate the URL for the OSADL (Open Source Automation Development Lab) page of a license.
@@ -110,6 +130,8 @@ class LicenseUtil(ScanossBase):
110
130
  :return: The URL of the OSADL page for the given license
111
131
  """
112
132
  return f'{self.BASE_OSADL_URL}/{spdxid}.txt'
133
+
134
+
113
135
  #
114
136
  # End of LicenseUtil Class
115
137
  #
scanoss/results.py CHANGED
@@ -1,25 +1,25 @@
1
1
  """
2
- SPDX-License-Identifier: MIT
3
-
4
- Copyright (c) 2024, SCANOSS
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
2
+ SPDX-License-Identifier: MIT
3
+
4
+ Copyright (c) 2024, SCANOSS
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
23
  """
24
24
 
25
25
  import json
@@ -27,27 +27,27 @@ from typing import Any, Dict, List
27
27
 
28
28
  from .scanossbase import ScanossBase
29
29
 
30
- MATCH_TYPES = ["file", "snippet"]
31
- STATUSES = ["pending", "identified"]
30
+ MATCH_TYPES = ['file', 'snippet']
31
+ STATUSES = ['pending', 'identified']
32
32
 
33
33
 
34
34
  AVAILABLE_FILTER_VALUES = {
35
- "match_type": [e for e in MATCH_TYPES],
36
- "status": [e for e in STATUSES],
35
+ 'match_type': [e for e in MATCH_TYPES],
36
+ 'status': [e for e in STATUSES],
37
37
  }
38
38
 
39
39
 
40
40
  ARG_TO_FILTER_MAP = {
41
- "match_type": "id",
42
- "status": "status",
41
+ 'match_type': 'id',
42
+ 'status': 'status',
43
43
  }
44
44
 
45
45
  PENDING_IDENTIFICATION_FILTERS = {
46
- "match_type": ["file", "snippet"],
47
- "status": ["pending"],
46
+ 'match_type': ['file', 'snippet'],
47
+ 'status': ['pending'],
48
48
  }
49
49
 
50
- AVAILABLE_OUTPUT_FORMATS = ["json", "plain"]
50
+ AVAILABLE_OUTPUT_FORMATS = ['json', 'plain']
51
51
 
52
52
 
53
53
  class Results(ScanossBase):
@@ -95,11 +95,11 @@ class Results(ScanossBase):
95
95
  Returns:
96
96
  Dict[str, Any]: The parsed JSON data
97
97
  """
98
- with open(file, "r") as jsonfile:
98
+ with open(file, 'r') as jsonfile:
99
99
  try:
100
100
  return json.load(jsonfile)
101
101
  except Exception as e:
102
- self.print_stderr(f"ERROR: Problem parsing input JSON: {e}")
102
+ self.print_stderr(f'ERROR: Problem parsing input JSON: {e}')
103
103
 
104
104
  def _load_and_transform(self, file: str) -> List[Dict[str, Any]]:
105
105
  """
@@ -143,7 +143,7 @@ class Results(ScanossBase):
143
143
 
144
144
  @staticmethod
145
145
  def _extract_comma_separated_values(values: str):
146
- return [value.strip() for value in values.split(",")]
146
+ return [value.strip() for value in values.split(',')]
147
147
 
148
148
  def apply_filters(self):
149
149
  """Apply the filters to the data"""
@@ -172,14 +172,11 @@ class Results(ScanossBase):
172
172
 
173
173
  @staticmethod
174
174
  def _validate_filter_values(filter_key: str, filter_value: List[str]):
175
- if any(
176
- value not in AVAILABLE_FILTER_VALUES.get(filter_key, [])
177
- for value in filter_value
178
- ):
179
- valid_values = ", ".join(AVAILABLE_FILTER_VALUES.get(filter_key, []))
175
+ if any(value not in AVAILABLE_FILTER_VALUES.get(filter_key, []) for value in filter_value):
176
+ valid_values = ', '.join(AVAILABLE_FILTER_VALUES.get(filter_key, []))
180
177
  raise Exception(
181
178
  f"ERROR: Invalid filter value '{filter_value}' for filter '{filter_key.value}'. "
182
- f"Valid values are: {valid_values}"
179
+ f'Valid values are: {valid_values}'
183
180
  )
184
181
 
185
182
  def get_pending_identifications(self):
@@ -226,9 +223,7 @@ class Results(ScanossBase):
226
223
  Args:
227
224
  file (str, optional): Output file. Defaults to None.
228
225
  """
229
- self.print_to_file_or_stdout(
230
- json.dumps(self._format_json_output(), indent=2), file
231
- )
226
+ self.print_to_file_or_stdout(json.dumps(self._format_json_output(), indent=2), file)
232
227
 
233
228
  def _format_json_output(self):
234
229
  """
@@ -240,15 +235,11 @@ class Results(ScanossBase):
240
235
  formatted_data.append(
241
236
  {
242
237
  'file': item.get('filename'),
243
- 'status': item.get('status', "N/A"),
238
+ 'status': item.get('status', 'N/A'),
244
239
  'match_type': item['id'],
245
- 'matched': item.get('matched', "N/A"),
246
- 'purl': (item.get('purl')[0] if item.get('purl') else "N/A"),
247
- 'license': (
248
- item.get('licenses')[0].get('name', "N/A")
249
- if item.get('licenses')
250
- else "N/A"
251
- ),
240
+ 'matched': item.get('matched', 'N/A'),
241
+ 'purl': (item.get('purl')[0] if item.get('purl') else 'N/A'),
242
+ 'license': (item.get('licenses')[0].get('name', 'N/A') if item.get('licenses') else 'N/A'),
252
243
  }
253
244
  )
254
245
  return {'results': formatted_data, 'total': len(formatted_data)}
@@ -263,7 +254,7 @@ class Results(ScanossBase):
263
254
  None
264
255
  """
265
256
  if not self.data:
266
- return self.print_stderr("No results to present")
257
+ return self.print_stderr('No results to present')
267
258
  self.print_to_file_or_stdout(self._format_plain_output(), file)
268
259
 
269
260
  def _present_stdout(self):
@@ -273,7 +264,7 @@ class Results(ScanossBase):
273
264
  None
274
265
  """
275
266
  if not self.data:
276
- return self.print_stderr("No results to present")
267
+ return self.print_stderr('No results to present')
277
268
  self.print_to_file_or_stdout(self._format_plain_output())
278
269
 
279
270
  def _format_plain_output(self):
@@ -281,9 +272,9 @@ class Results(ScanossBase):
281
272
  Format the output data into a plain text string
282
273
  """
283
274
 
284
- formatted = ""
275
+ formatted = ''
285
276
  for item in self.data:
286
- formatted += f"{self._format_plain_output_item(item)} \n"
277
+ formatted += f'{self._format_plain_output_item(item)} \n'
287
278
  return formatted
288
279
 
289
280
  @staticmethod
@@ -292,10 +283,10 @@ class Results(ScanossBase):
292
283
  licenses = item.get('licenses', [])
293
284
 
294
285
  return (
295
- f"File: {item.get('filename')}\n"
296
- f"Match type: {item.get('id')}\n"
297
- f"Status: {item.get('status', 'N/A')}\n"
298
- f"Matched: {item.get('matched', 'N/A')}\n"
299
- f"Purl: {purls[0] if purls else 'N/A'}\n"
300
- f"License: {licenses[0].get('name', 'N/A') if licenses else 'N/A'}\n"
286
+ f'File: {item.get("filename")}\n'
287
+ f'Match type: {item.get("id")}\n'
288
+ f'Status: {item.get("status", "N/A")}\n'
289
+ f'Matched: {item.get("matched", "N/A")}\n'
290
+ f'Purl: {purls[0] if purls else "N/A"}\n'
291
+ f'License: {licenses[0].get("name", "N/A") if licenses else "N/A"}\n'
301
292
  )
scanoss/scancodedeps.py CHANGED
@@ -1,25 +1,25 @@
1
1
  """
2
- SPDX-License-Identifier: MIT
2
+ SPDX-License-Identifier: MIT
3
3
 
4
- Copyright (c) 2021, SCANOSS
4
+ Copyright (c) 2021, SCANOSS
5
5
 
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
12
 
13
- The above copyright notice and this permission notice shall be included in
14
- all copies or substantial portions of the Software.
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
15
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- THE SOFTWARE.
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
23
  """
24
24
 
25
25
  import json
@@ -33,8 +33,17 @@ class ScancodeDeps(ScanossBase):
33
33
  """
34
34
  SCANOSS dependency scanning class
35
35
  """
36
- def __init__(self, debug: bool = False, quiet: bool = False, trace: bool = False, output_file: str = None,
37
- scan_output: str = None, timeout: int = 600, sc_command: str = None):
36
+
37
+ def __init__(
38
+ self,
39
+ debug: bool = False,
40
+ quiet: bool = False,
41
+ trace: bool = False,
42
+ output_file: str = None,
43
+ scan_output: str = None,
44
+ timeout: int = 600,
45
+ sc_command: str = None,
46
+ ):
38
47
  """
39
48
  Initialise ScancodeDeps class
40
49
  """
@@ -54,12 +63,11 @@ class ScancodeDeps(ScanossBase):
54
63
  if not outfile and self.scan_output:
55
64
  outfile = self.scan_output
56
65
  if outfile:
57
- with open(outfile, "a") as rf:
66
+ with open(outfile, 'a') as rf:
58
67
  rf.write(string + '\n')
59
68
  else:
60
69
  print(string)
61
70
 
62
-
63
71
  def remove_interim_file(self, output_file: str = None):
64
72
  """
65
73
  Remove the temporary Scancode interim file
@@ -86,7 +94,7 @@ class ScancodeDeps(ScanossBase):
86
94
  self.print_debug(f'Processing Scancode results into Dependency data...')
87
95
  files = []
88
96
  for t in data:
89
- if t == 'files': # Only interested in 'files' details
97
+ if t == 'files': # Only interested in 'files' details
90
98
  files_details = data.get(t)
91
99
  if not files_details or files_details == '':
92
100
  continue
@@ -121,7 +129,7 @@ class ScancodeDeps(ScanossBase):
121
129
  dp_data = {'purl': dp}
122
130
  rq = d.get('extracted_requirement') # scancode format 2.0
123
131
  if not rq or rq == '':
124
- rq = d.get('requirement') # scancode format 1.0
132
+ rq = d.get('requirement') # scancode format 1.0
125
133
  # skip requirement if it ends with the purl (i.e. exact version) or if it's local (file)
126
134
  if rq and rq != '' and not dp.endswith(rq) and not rq.startswith('file:'):
127
135
  dp_data['requirement'] = rq
@@ -206,17 +214,32 @@ class ScancodeDeps(ScanossBase):
206
214
  output_file = self.output_file
207
215
  try:
208
216
  open(output_file, 'w').close()
209
- self.print_trace(f'About to execute {self.sc_command} -p --only-findings --quiet --json {output_file}'
210
- f' {what_to_scan}')
211
- result = subprocess.run([self.sc_command, '-p', '--only-findings', '--quiet', '--strip-root', '--json',
212
- output_file, what_to_scan],
213
- cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
214
- text=True, timeout=self.timeout
215
- )
217
+ self.print_trace(
218
+ f'About to execute {self.sc_command} -p --only-findings --quiet --json {output_file} {what_to_scan}'
219
+ )
220
+ result = subprocess.run(
221
+ [
222
+ self.sc_command,
223
+ '-p',
224
+ '--only-findings',
225
+ '--quiet',
226
+ '--strip-root',
227
+ '--json',
228
+ output_file,
229
+ what_to_scan,
230
+ ],
231
+ cwd=os.getcwd(),
232
+ stdout=subprocess.PIPE,
233
+ stderr=subprocess.STDOUT,
234
+ text=True,
235
+ timeout=self.timeout,
236
+ )
216
237
  self.print_trace(f'Subprocess return: {result}')
217
238
  if result.returncode:
218
- self.print_stderr(f'ERROR: Scancode dependency scan of {what_to_scan} failed with exit code'
219
- f' {result.returncode}:\n{result.stdout}')
239
+ self.print_stderr(
240
+ f'ERROR: Scancode dependency scan of {what_to_scan} failed with exit code'
241
+ f' {result.returncode}:\n{result.stdout}'
242
+ )
220
243
  return False
221
244
  except subprocess.TimeoutExpired as e:
222
245
  self.print_stderr(f'ERROR: Timed out attempting to run scancode dependency scan on {what_to_scan}: {e}')
@@ -245,21 +268,21 @@ class ScancodeDeps(ScanossBase):
245
268
  self.print_stderr(f'ERROR: Problem loading input JSON: {e}')
246
269
  return None
247
270
 
248
-
249
271
  @staticmethod
250
- def __remove_dep_scope(deps: json)->json:
272
+ def __remove_dep_scope(deps: json) -> json:
251
273
  """
252
274
  :param deps: dependencies with scopes
253
275
  :return dependencies without scopes
254
276
  """
255
- files = deps.get("files")
277
+ files = deps.get('files')
256
278
  for file in files:
257
279
  if 'purls' in file:
258
- purls = file.get("purls")
280
+ purls = file.get('purls')
259
281
  for purl in purls:
260
- purl.pop("scope",None)
282
+ purl.pop('scope', None)
283
+
284
+ return {'files': files}
261
285
 
262
- return {"files": files }
263
286
 
264
287
  #
265
288
  # End of ScancodeDeps Class