Skip to content

Commit 6267260

Browse files
Recognize manifestfile as License File
Signed-off-by: Wonjae Park <[email protected]>
1 parent f5af542 commit 6267260

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ._scan_item import is_exclude_file
1414
from ._scan_item import replace_word
1515
from ._scan_item import is_notice_file
16+
from ._scan_item import is_manifest_file
1617
from typing import Tuple
1718

1819
logger = logging.getLogger(constant.LOGGER_NAME)
@@ -169,6 +170,10 @@ def parsing_scancode_32_earlier(scancode_file_list: list, has_error: bool = Fals
169170
set(license_expression_list))
170171
result_item.comment = ','.join(license_expression_list)
171172

173+
# Check if this is a manifest file with license information
174+
if is_manifest_file(file_path):
175+
result_item.is_license_text = True
176+
172177
if is_exclude_file(file_path, prev_dir, prev_dir_value):
173178
result_item.exclude = True
174179
scancode_file_item.append(result_item)
@@ -269,6 +274,11 @@ def parsing_scancode_32_later(
269274

270275
result_item.exclude = is_exclude_file(file_path)
271276
result_item.is_license_text = file.get("percentage_of_license_text", 0) > 90 or is_notice_file(file_path)
277+
278+
# Check if this is a manifest file with license information
279+
if is_manifest_file(file_path) and len(license_detected) > 0:
280+
result_item.is_license_text = True
281+
272282
scancode_file_item.append(result_item)
273283
except Exception as ex:
274284
msg.append(f"Error Parsing item: {ex}")

src/fosslight_source/_scan_item.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
_notice_filename = ['licen[cs]e[s]?', 'notice[s]?', 'legal', 'copyright[s]?', 'copying*', 'patent[s]?', 'unlicen[cs]e', 'eula',
1515
'[a,l]?gpl[-]?[1-3]?[.,-,_]?[0-1]?', 'mit', 'bsd[-]?[0-4]?', 'bsd[-]?[0-4][-]?clause[s]?',
1616
'apache[-,_]?[1-2]?[.,-,_]?[0-2]?']
17+
_manifest_filename = ['requirements\\.txt', 'setup\\.py', 'pyproject\\.toml', 'pnpm-lock\\.yaml', 'package\\.json',
18+
'pom\\.xml', 'build\\.gradle', 'pubspec\\.yaml', 'Podfile\\.lock', 'Package\\.resolved',
19+
'Cartfile\\.resolved', 'go\\.mod', 'packages\\.config', 'Chart\\.yaml', 'Cargo\\.toml']
1720
_exclude_filename = ["changelog", "config.guess", "config.sub", "changes", "ltmain.sh",
1821
"configure", "configure.ac", "depcomp", "compile", "missing", "makefile"]
1922
_exclude_extension = [".m4", ".in", ".po"]
@@ -140,3 +143,11 @@ def is_notice_file(file_path: str) -> bool:
140143
file_path = file_path.lower()
141144
filename = os.path.basename(file_path)
142145
return bool(re.match(pattern, filename))
146+
147+
148+
def is_manifest_file(file_path: str) -> bool:
149+
"""Check if the file is a package manager manifest file."""
150+
pattern = r"({})$".format("|".join(_manifest_filename))
151+
file_path = file_path.lower()
152+
filename = os.path.basename(file_path)
153+
return bool(re.match(pattern, filename))

0 commit comments

Comments
 (0)