fosslight-source 2.3.16__tar.gz → 2.3.18__tar.gz
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-2.3.16/src/fosslight_source.egg-info → fosslight_source-2.3.18}/PKG-INFO +2 -2
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/pyproject.toml +2 -2
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/cli.py +31 -20
- {fosslight_source-2.3.16 → fosslight_source-2.3.18/src/fosslight_source.egg-info}/PKG-INFO +2 -2
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/SOURCES.txt +1 -1
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/requires.txt +1 -1
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_multi_value_order.py +1 -1
- fosslight_source-2.3.18/tests/test_spdx_license_text.py +54 -0
- fosslight_source-2.3.16/src/fosslight_source/_merge.py +0 -270
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/LICENSE +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/MANIFEST.in +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/README.md +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/setup.cfg +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/__init__.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_exclude.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_help.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_kb_client.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_license_matched.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_parsing_scancode_file_item.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_parsing_scanoss_file.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_scan_item.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_scancode_ignore_binaries.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/run_manifest_extractor.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/run_scancode.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/run_scanoss.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/run_spdx_extractor.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/dependency_links.txt +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/entry_points.txt +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/top_level.txt +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_kb_ssl.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_manifest_android_bp.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_manifest_composer.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_manifest_pyproject.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_manifest_recommended_scenarios.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_manifest_setup_cfg.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_parsing_unknown_spdx.py +0 -0
- {fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_tox.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fosslight_source
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.18
|
|
4
4
|
Summary: FOSSLight Source Scanner
|
|
5
5
|
Author: LG Electronics
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -20,7 +20,7 @@ Requires-Dist: setuptools<=80.10.2
|
|
|
20
20
|
Requires-Dist: pyparsing
|
|
21
21
|
Requires-Dist: scanoss>=1.45.0
|
|
22
22
|
Requires-Dist: XlsxWriter
|
|
23
|
-
Requires-Dist: fosslight_util>=2.2.
|
|
23
|
+
Requires-Dist: fosslight_util>=2.2.21
|
|
24
24
|
Requires-Dist: PyYAML
|
|
25
25
|
Requires-Dist: wheel>=0.38.1
|
|
26
26
|
Requires-Dist: intbitset
|
|
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "fosslight_source"
|
|
10
|
-
version = "2.3.
|
|
10
|
+
version = "2.3.18"
|
|
11
11
|
description = "FOSSLight Source Scanner"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
license = "Apache-2.0"
|
|
@@ -29,7 +29,7 @@ dependencies = [
|
|
|
29
29
|
"pyparsing",
|
|
30
30
|
"scanoss>=1.45.0",
|
|
31
31
|
"XlsxWriter",
|
|
32
|
-
"fosslight_util>=2.2.
|
|
32
|
+
"fosslight_util>=2.2.21",
|
|
33
33
|
"PyYAML",
|
|
34
34
|
"wheel>=0.38.1",
|
|
35
35
|
"intbitset",
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import sys
|
|
7
7
|
import os
|
|
8
|
-
import platform
|
|
9
8
|
import time
|
|
10
9
|
import warnings
|
|
11
10
|
import logging
|
|
@@ -37,10 +36,7 @@ from fosslight_util.time import current_timestamp_utc, format_running_time, time
|
|
|
37
36
|
from fosslight_util.oss_item import ScannerItem
|
|
38
37
|
from typing import Optional, Tuple
|
|
39
38
|
import shutil
|
|
40
|
-
from .
|
|
41
|
-
_add_pre_merge_sheet,
|
|
42
|
-
merge_results_by_folder
|
|
43
|
-
)
|
|
39
|
+
from fosslight_util.merge import _add_pre_merge_sheet, merge_results_by_folder
|
|
44
40
|
|
|
45
41
|
|
|
46
42
|
SRC_SHEET_NAME = 'SRC_FL_Source'
|
|
@@ -171,16 +167,11 @@ def create_report_file(
|
|
|
171
167
|
# If -o does not contains file name, set default name
|
|
172
168
|
while len(output_files) < len(output_extensions):
|
|
173
169
|
output_files.append(None)
|
|
174
|
-
to_remove = [] # elements of spdx format on windows that should be removed
|
|
175
170
|
for i, output_extension in enumerate(output_extensions):
|
|
176
171
|
if output_files[i] is None or output_files[i] == "":
|
|
177
172
|
if formats:
|
|
178
173
|
if formats[i].startswith('spdx'):
|
|
179
|
-
|
|
180
|
-
logger.warning(f'{formats[i]} is not supported on Windows.Please remove {formats[i]} from format.')
|
|
181
|
-
to_remove.append(i)
|
|
182
|
-
else:
|
|
183
|
-
output_files[i] = f"fosslight_spdx_src_{name_time}"
|
|
174
|
+
output_files[i] = f"fosslight_spdx_src_{name_time}"
|
|
184
175
|
elif formats[i].startswith('cyclonedx'):
|
|
185
176
|
output_files[i] = f'fosslight_cyclonedx_src_{name_time}'
|
|
186
177
|
else:
|
|
@@ -193,14 +184,6 @@ def create_report_file(
|
|
|
193
184
|
output_files[i] = f"fosslight_opossum_src_{name_time}"
|
|
194
185
|
else:
|
|
195
186
|
output_files[i] = f"fosslight_report_src_{name_time}"
|
|
196
|
-
for index in sorted(to_remove, reverse=True):
|
|
197
|
-
# remove elements of spdx format on windows
|
|
198
|
-
del output_files[index]
|
|
199
|
-
del output_extensions[index]
|
|
200
|
-
del formats[index]
|
|
201
|
-
if len(output_extensions) < 1:
|
|
202
|
-
sys.exit(0)
|
|
203
|
-
|
|
204
187
|
if not correct_filepath:
|
|
205
188
|
correct_filepath = path_to_scan
|
|
206
189
|
|
|
@@ -259,6 +242,31 @@ def create_report_file(
|
|
|
259
242
|
scan_item = correct_item
|
|
260
243
|
logger.info("Success to correct with yaml.")
|
|
261
244
|
|
|
245
|
+
if license_list and any(output_format.startswith("spdx") for output_format in formats):
|
|
246
|
+
matched_texts_by_file = {}
|
|
247
|
+
for matched_license in license_list.values():
|
|
248
|
+
if not matched_license.matched_text:
|
|
249
|
+
continue
|
|
250
|
+
for matched_path in matched_license.files:
|
|
251
|
+
path_key = os.path.normcase(os.path.normpath(matched_path.replace("\\", "/")))
|
|
252
|
+
matched_texts_by_file.setdefault(path_key, []).append(matched_license)
|
|
253
|
+
|
|
254
|
+
for file_item in scan_item.file_items.get(PKG_NAME, []):
|
|
255
|
+
path_key = os.path.normcase(os.path.normpath(file_item.source_name_or_path.replace("\\", "/")))
|
|
256
|
+
for oss_item in file_item.oss_items:
|
|
257
|
+
if oss_item.exclude:
|
|
258
|
+
continue
|
|
259
|
+
for license_name in oss_item.license:
|
|
260
|
+
for matched_license in matched_texts_by_file.get(path_key, []):
|
|
261
|
+
declares_license = re.search(
|
|
262
|
+
r"(?:SPDX[-\s]+License[-\s]+Identifier\s*:\s*|\blicense\s*=\s*['\"]\s*)"
|
|
263
|
+
+ re.escape(license_name) + r"(?=[,'\"\s]|$)",
|
|
264
|
+
matched_license.matched_text, re.IGNORECASE,
|
|
265
|
+
)
|
|
266
|
+
if matched_license.license.casefold() == license_name.casefold() or declares_license:
|
|
267
|
+
oss_item.license_texts.setdefault(license_name, matched_license.matched_text)
|
|
268
|
+
break
|
|
269
|
+
|
|
262
270
|
finish_time = current_timestamp_utc()
|
|
263
271
|
scan_item.set_cover_finish_time(finish_time)
|
|
264
272
|
|
|
@@ -652,9 +660,12 @@ def run_scanners(
|
|
|
652
660
|
if not selected_scanner:
|
|
653
661
|
selected_scanner = ALL_MODE
|
|
654
662
|
if selected_scanner in ['scancode', ALL_MODE]:
|
|
663
|
+
need_matched_license = print_matched_text or any(
|
|
664
|
+
output_format.startswith("spdx") for output_format in formats
|
|
665
|
+
)
|
|
655
666
|
success, result_log[RESULT_KEY], scancode_result, license_list = run_scan(
|
|
656
667
|
path_to_scan, output_file_name, write_json_file, num_cores, True,
|
|
657
|
-
|
|
668
|
+
need_matched_license, formats, called_by_cli, time_out, correct_mode,
|
|
658
669
|
correct_filepath, path_to_exclude,
|
|
659
670
|
hide_progress=hide_progress,
|
|
660
671
|
ui_mode=ui_mode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fosslight_source
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.18
|
|
4
4
|
Summary: FOSSLight Source Scanner
|
|
5
5
|
Author: LG Electronics
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -20,7 +20,7 @@ Requires-Dist: setuptools<=80.10.2
|
|
|
20
20
|
Requires-Dist: pyparsing
|
|
21
21
|
Requires-Dist: scanoss>=1.45.0
|
|
22
22
|
Requires-Dist: XlsxWriter
|
|
23
|
-
Requires-Dist: fosslight_util>=2.2.
|
|
23
|
+
Requires-Dist: fosslight_util>=2.2.21
|
|
24
24
|
Requires-Dist: PyYAML
|
|
25
25
|
Requires-Dist: wheel>=0.38.1
|
|
26
26
|
Requires-Dist: intbitset
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/SOURCES.txt
RENAMED
|
@@ -7,7 +7,6 @@ src/fosslight_source/_exclude.py
|
|
|
7
7
|
src/fosslight_source/_help.py
|
|
8
8
|
src/fosslight_source/_kb_client.py
|
|
9
9
|
src/fosslight_source/_license_matched.py
|
|
10
|
-
src/fosslight_source/_merge.py
|
|
11
10
|
src/fosslight_source/_parsing_scancode_file_item.py
|
|
12
11
|
src/fosslight_source/_parsing_scanoss_file.py
|
|
13
12
|
src/fosslight_source/_scan_item.py
|
|
@@ -31,4 +30,5 @@ tests/test_manifest_recommended_scenarios.py
|
|
|
31
30
|
tests/test_manifest_setup_cfg.py
|
|
32
31
|
tests/test_multi_value_order.py
|
|
33
32
|
tests/test_parsing_unknown_spdx.py
|
|
33
|
+
tests/test_spdx_license_text.py
|
|
34
34
|
tests/test_tox.py
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
"""Stable order for multi-value License / Copyright cells."""
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from fosslight_util.merge import _get_top_merge_values
|
|
6
6
|
from fosslight_source._scan_item import SourceItem
|
|
7
7
|
|
|
8
8
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright (c) 2026 LG Electronics Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
from spdx_tools.spdx.parser.parse_anything import parse_file
|
|
8
|
+
from spdx_tools.spdx.validation.document_validator import validate_full_spdx_document
|
|
9
|
+
|
|
10
|
+
from fosslight_source import cli as source_cli
|
|
11
|
+
from fosslight_source._license_matched import MatchedLicense
|
|
12
|
+
from fosslight_source._scan_item import SourceItem
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.mark.parametrize("matched_text, expected_text", [
|
|
16
|
+
(' license="BSD",', ' license="BSD",'),
|
|
17
|
+
("", "BSD"),
|
|
18
|
+
])
|
|
19
|
+
def test_spdx_uses_scancode_matched_text_without_reference_sheet(
|
|
20
|
+
tmp_path, monkeypatch, matched_text, expected_text
|
|
21
|
+
):
|
|
22
|
+
project = tmp_path / "project"
|
|
23
|
+
project.mkdir()
|
|
24
|
+
(project / "setup.py").write_text('license="BSD"\n', encoding="utf-8")
|
|
25
|
+
output = tmp_path / "reports"
|
|
26
|
+
source_item = SourceItem("setup.py")
|
|
27
|
+
source_item.checksum = "a" * 40
|
|
28
|
+
source_item.licenses = ["BSD-3-Clause"]
|
|
29
|
+
matched_license = MatchedLicense("BSD-3-Clause", "", matched_text, "setup.py")
|
|
30
|
+
license_list = {matched_license.license + matched_license.matched_text: matched_license}
|
|
31
|
+
received_need_matched_text = []
|
|
32
|
+
|
|
33
|
+
def run_scancode(*args, **kwargs):
|
|
34
|
+
received_need_matched_text.append(args[5])
|
|
35
|
+
return True, "True", [source_item], license_list
|
|
36
|
+
|
|
37
|
+
monkeypatch.chdir(tmp_path)
|
|
38
|
+
monkeypatch.setattr(source_cli, "run_scan", run_scancode)
|
|
39
|
+
|
|
40
|
+
success, message, scan_item, _licenses, _scanoss_result = source_cli.run_scanners(
|
|
41
|
+
str(project), str(output), selected_scanner="scancode", formats=["spdx-json"],
|
|
42
|
+
print_matched_text=False, correct_mode=False, all_exclude_mode=([], [], set(), 1),
|
|
43
|
+
hide_progress=True,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
assert success, message
|
|
47
|
+
assert received_need_matched_text == [True]
|
|
48
|
+
assert "scancode_reference" not in scan_item.external_sheets
|
|
49
|
+
assert scan_item.file_items[source_cli.PKG_NAME][0].oss_items[0].license == ["BSD"]
|
|
50
|
+
document = parse_file(str(next(output.glob("*.json"))))
|
|
51
|
+
assert validate_full_spdx_document(document) == []
|
|
52
|
+
assert document.extracted_licensing_info[0].license_name == "BSD"
|
|
53
|
+
assert document.extracted_licensing_info[0].extracted_text == expected_text
|
|
54
|
+
assert {str(value) for value in document.files[0].license_info_in_file} == {"LicenseRef-BSD"}
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Copyright (c) 2020 LG Electronics Inc.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
import os
|
|
7
|
-
from collections import Counter
|
|
8
|
-
|
|
9
|
-
from fosslight_util.constant import COMMENT_DELIMITER
|
|
10
|
-
|
|
11
|
-
from ._scan_item import SourceItem
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _get_source_rows_to_print(source_items: list) -> list:
|
|
15
|
-
source_rows = []
|
|
16
|
-
for source_item in source_items:
|
|
17
|
-
source_rows.extend(source_item.get_print_array())
|
|
18
|
-
return source_rows
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def _add_pre_merge_sheet(scan_item, pre_merge_sheet_name: str, header_row: list, pkg_name: str) -> None:
|
|
22
|
-
external_sheets = getattr(scan_item, "external_sheets", {}) or {}
|
|
23
|
-
external_sheets[pre_merge_sheet_name] = [
|
|
24
|
-
header_row,
|
|
25
|
-
*_get_source_rows_to_print(scan_item.file_items.get(pkg_name, [])),
|
|
26
|
-
]
|
|
27
|
-
scan_item.external_sheets = external_sheets
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def _normalize_merge_text(value: str) -> str:
|
|
31
|
-
return value.strip() if value else ""
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def _iter_merge_values(values) -> list:
|
|
35
|
-
if not values:
|
|
36
|
-
return []
|
|
37
|
-
if isinstance(values, str):
|
|
38
|
-
return [values]
|
|
39
|
-
return values
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _normalize_merge_licenses(licenses) -> tuple:
|
|
43
|
-
return tuple(sorted([lic.strip() for lic in _iter_merge_values(licenses) if lic and lic.strip()]))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def _normalize_merge_downloads(downloads) -> tuple:
|
|
47
|
-
if not downloads:
|
|
48
|
-
return ()
|
|
49
|
-
if isinstance(downloads, str):
|
|
50
|
-
downloads = [downloads]
|
|
51
|
-
return tuple(sorted([dl.strip() for dl in downloads if dl and dl.strip()]))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _iter_merge_rows(item: SourceItem):
|
|
55
|
-
if item.oss_items:
|
|
56
|
-
for oss_item in item.oss_items:
|
|
57
|
-
name = _normalize_merge_text(oss_item.name) or _normalize_merge_text(item.oss_name)
|
|
58
|
-
version = _normalize_merge_text(oss_item.version) or _normalize_merge_text(item.oss_version)
|
|
59
|
-
licenses = _normalize_merge_licenses(oss_item.license or item.licenses)
|
|
60
|
-
downloads = _normalize_merge_downloads(oss_item.download_location or item.download_location)
|
|
61
|
-
yield name, version, licenses, downloads
|
|
62
|
-
else:
|
|
63
|
-
yield (
|
|
64
|
-
_normalize_merge_text(item.oss_name),
|
|
65
|
-
_normalize_merge_text(item.oss_version),
|
|
66
|
-
_normalize_merge_licenses(item.licenses),
|
|
67
|
-
_normalize_merge_downloads(item.download_location),
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def _get_item_oss_name(item: SourceItem) -> str:
|
|
72
|
-
for name, _, _, _ in _iter_merge_rows(item):
|
|
73
|
-
if name:
|
|
74
|
-
return name
|
|
75
|
-
return ""
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _get_item_oss_version(item: SourceItem) -> str:
|
|
79
|
-
for _, version, _, _ in _iter_merge_rows(item):
|
|
80
|
-
if version:
|
|
81
|
-
return version
|
|
82
|
-
return ""
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def _get_merge_licenses(scan_item: SourceItem) -> tuple:
|
|
86
|
-
for _, _, licenses, _ in _iter_merge_rows(scan_item):
|
|
87
|
-
if licenses:
|
|
88
|
-
return licenses
|
|
89
|
-
return ()
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def _get_merge_download_locations(scan_item: SourceItem) -> tuple:
|
|
93
|
-
for _, _, _, downloads in _iter_merge_rows(scan_item):
|
|
94
|
-
if downloads:
|
|
95
|
-
return downloads
|
|
96
|
-
return ()
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
def _get_merge_field_value(scan_items: list, value_getter):
|
|
100
|
-
for scan_item in scan_items:
|
|
101
|
-
value = value_getter(scan_item)
|
|
102
|
-
if value:
|
|
103
|
-
return value
|
|
104
|
-
return ""
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _get_top_merge_values(scan_items: list, value_getter) -> list:
|
|
108
|
-
values = []
|
|
109
|
-
for scan_item in scan_items:
|
|
110
|
-
for value in _iter_merge_values(value_getter(scan_item)):
|
|
111
|
-
normalized_value = _normalize_merge_text(value)
|
|
112
|
-
if normalized_value:
|
|
113
|
-
values.append(normalized_value)
|
|
114
|
-
ranked = sorted(Counter(values).items(), key=lambda entry: (-entry[1], entry[0]))
|
|
115
|
-
return [value for value, _ in ranked[:3]]
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def _can_merge_folder(scan_items: list) -> bool:
|
|
119
|
-
if len(scan_items) <= 1:
|
|
120
|
-
return False
|
|
121
|
-
|
|
122
|
-
ref_name = None
|
|
123
|
-
ref_version = None
|
|
124
|
-
ref_licenses = None
|
|
125
|
-
ref_downloads = None
|
|
126
|
-
|
|
127
|
-
for item in scan_items:
|
|
128
|
-
for name, version, licenses, downloads in _iter_merge_rows(item):
|
|
129
|
-
if name:
|
|
130
|
-
if ref_name is None:
|
|
131
|
-
ref_name = name
|
|
132
|
-
elif name != ref_name:
|
|
133
|
-
return False
|
|
134
|
-
|
|
135
|
-
if version:
|
|
136
|
-
if ref_version is None:
|
|
137
|
-
ref_version = version
|
|
138
|
-
elif version != ref_version:
|
|
139
|
-
return False
|
|
140
|
-
|
|
141
|
-
if licenses:
|
|
142
|
-
if ref_licenses is None:
|
|
143
|
-
ref_licenses = licenses
|
|
144
|
-
elif licenses != ref_licenses:
|
|
145
|
-
return False
|
|
146
|
-
|
|
147
|
-
if downloads:
|
|
148
|
-
if ref_downloads is None:
|
|
149
|
-
ref_downloads = downloads
|
|
150
|
-
elif downloads != ref_downloads:
|
|
151
|
-
return False
|
|
152
|
-
|
|
153
|
-
return True
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def _get_merged_comments(scan_items: list) -> str:
|
|
157
|
-
comments = []
|
|
158
|
-
for item in scan_items:
|
|
159
|
-
val = item.comment
|
|
160
|
-
if val:
|
|
161
|
-
parts = [p.strip() for p in val.split(COMMENT_DELIMITER) if p.strip()]
|
|
162
|
-
for p in parts:
|
|
163
|
-
if p not in comments:
|
|
164
|
-
comments.append(p)
|
|
165
|
-
if not comments:
|
|
166
|
-
return ""
|
|
167
|
-
|
|
168
|
-
return COMMENT_DELIMITER.join(comments)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
def _create_merged_item(scan_items: list, merge_path: str) -> SourceItem:
|
|
172
|
-
merged_path = f"{merge_path} ({len(scan_items)})"
|
|
173
|
-
merged_item = SourceItem(merged_path)
|
|
174
|
-
merged_item.oss_name = _get_merge_field_value(scan_items, lambda item: _normalize_merge_text(_get_item_oss_name(item)))
|
|
175
|
-
merged_item.oss_version = _get_merge_field_value(scan_items, lambda item: _normalize_merge_text(_get_item_oss_version(item)))
|
|
176
|
-
merged_licenses = _get_merge_field_value(scan_items, _get_merge_licenses)
|
|
177
|
-
merged_item.licenses = list(merged_licenses) if merged_licenses else []
|
|
178
|
-
merged_downloads = _get_merge_field_value(scan_items, _get_merge_download_locations)
|
|
179
|
-
merged_item.download_location = list(merged_downloads) if merged_downloads else []
|
|
180
|
-
merged_copyrights = _get_top_merge_values(scan_items, lambda item: item.copyright)
|
|
181
|
-
merged_item.copyright = merged_copyrights if merged_copyrights else []
|
|
182
|
-
merged_comments = _get_merged_comments(scan_items)
|
|
183
|
-
if merged_comments:
|
|
184
|
-
merged_item.comment = merged_comments
|
|
185
|
-
merged_item.set_oss_item()
|
|
186
|
-
return merged_item
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def merge_results_by_folder(scan_result: list) -> list:
|
|
190
|
-
"""
|
|
191
|
-
Merge output rows within the same folder when OSS name, OSS version, license,
|
|
192
|
-
and download location are compatible.
|
|
193
|
-
|
|
194
|
-
A field is compatible when all non-empty values across rows are identical
|
|
195
|
-
(empty values are ignored). Each oss_item is treated as its own row. All eligible
|
|
196
|
-
rows in the folder must be compatible together; rows are not grouped by key subsets.
|
|
197
|
-
"""
|
|
198
|
-
# Build a folder tree first so merge never jumps straight to root ".".
|
|
199
|
-
merge_tree = {"items": [], "children": {}}
|
|
200
|
-
|
|
201
|
-
for scan_item in scan_result:
|
|
202
|
-
normalized_path = os.path.normpath(scan_item.source_name_or_path).replace("\\", "/")
|
|
203
|
-
path_parts = [part for part in normalized_path.split("/") if part and part != "."]
|
|
204
|
-
current_node = merge_tree
|
|
205
|
-
|
|
206
|
-
for folder_name in path_parts[:-1]:
|
|
207
|
-
current_node = current_node["children"].setdefault(folder_name, {"items": [], "children": {}})
|
|
208
|
-
current_node["items"].append(scan_item)
|
|
209
|
-
|
|
210
|
-
def merge_node(merge_node_item: dict, merge_path: str = "", depth: int = 0) -> tuple:
|
|
211
|
-
child_finalized = []
|
|
212
|
-
child_unfinalized = []
|
|
213
|
-
for folder_name, child_node in merge_node_item["children"].items():
|
|
214
|
-
child_path = f"{merge_path}/{folder_name}" if merge_path else folder_name
|
|
215
|
-
fin, unfin = merge_node(child_node, child_path, depth + 1)
|
|
216
|
-
child_finalized.extend(fin)
|
|
217
|
-
child_unfinalized.extend(unfin)
|
|
218
|
-
|
|
219
|
-
local_excluded = [item for item in merge_node_item["items"] if item.exclude]
|
|
220
|
-
local_eligible = [item for item in merge_node_item["items"] if not item.exclude]
|
|
221
|
-
|
|
222
|
-
all_eligible_candidates = list(local_eligible)
|
|
223
|
-
for _, g_items in child_unfinalized:
|
|
224
|
-
all_eligible_candidates.extend(g_items)
|
|
225
|
-
|
|
226
|
-
# We can merge under the current node if depth > 0 and we are combining multiple sources:
|
|
227
|
-
# e.g., local files + child groups, or multiple child groups, or multiple local files.
|
|
228
|
-
can_merge_here = (depth > 0) and (len(local_eligible) + len(child_unfinalized) > 1)
|
|
229
|
-
|
|
230
|
-
if can_merge_here:
|
|
231
|
-
if _can_merge_folder(all_eligible_candidates):
|
|
232
|
-
new_finalized = child_finalized + local_excluded
|
|
233
|
-
new_unfinalized = [(merge_path, all_eligible_candidates)]
|
|
234
|
-
return new_finalized, new_unfinalized
|
|
235
|
-
else:
|
|
236
|
-
# Compatibility broke at this level. We must finalize the subtrees.
|
|
237
|
-
finalized_child_groups = []
|
|
238
|
-
for c_path, c_items in child_unfinalized:
|
|
239
|
-
if len(c_items) > 1 and _can_merge_folder(c_items):
|
|
240
|
-
finalized_child_groups.append(_create_merged_item(c_items, c_path))
|
|
241
|
-
else:
|
|
242
|
-
finalized_child_groups.extend(c_items)
|
|
243
|
-
|
|
244
|
-
finalized_local = []
|
|
245
|
-
if len(local_eligible) > 1 and _can_merge_folder(local_eligible):
|
|
246
|
-
finalized_local.append(_create_merged_item(local_eligible, merge_path))
|
|
247
|
-
else:
|
|
248
|
-
finalized_local.extend(local_eligible)
|
|
249
|
-
|
|
250
|
-
new_finalized = child_finalized + local_excluded + finalized_child_groups + finalized_local
|
|
251
|
-
new_unfinalized = []
|
|
252
|
-
return new_finalized, new_unfinalized
|
|
253
|
-
else:
|
|
254
|
-
# We cannot merge or don't need to merge at this level (e.g. depth == 0 or only 1 source).
|
|
255
|
-
# We propagate everything up as unfinalized.
|
|
256
|
-
new_finalized = child_finalized + local_excluded
|
|
257
|
-
new_unfinalized = list(child_unfinalized)
|
|
258
|
-
if local_eligible:
|
|
259
|
-
new_unfinalized.append((merge_path, local_eligible))
|
|
260
|
-
return new_finalized, new_unfinalized
|
|
261
|
-
|
|
262
|
-
fin, unfin = merge_node(merge_tree)
|
|
263
|
-
finalized_results = list(fin)
|
|
264
|
-
for path, items in unfin:
|
|
265
|
-
if path and len(items) > 1 and _can_merge_folder(items):
|
|
266
|
-
finalized_results.append(_create_merged_item(items, path))
|
|
267
|
-
else:
|
|
268
|
-
finalized_results.extend(items)
|
|
269
|
-
|
|
270
|
-
return finalized_results
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_license_matched.py
RENAMED
|
File without changes
|
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/_parsing_scanoss_file.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/run_manifest_extractor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source/run_spdx_extractor.py
RENAMED
|
File without changes
|
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/src/fosslight_source.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_source-2.3.16 → fosslight_source-2.3.18}/tests/test_manifest_recommended_scenarios.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|