Skip to content

Commit 51533fc

Browse files
Recognize manifest file as License File (#210)
* Recognize manifest files as License File Signed-off-by: Wonjae Park <[email protected]>
1 parent f5af542 commit 51533fc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 8 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,9 @@ 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+
if is_manifest_file(file_path):
174+
result_item.is_license_text = True
175+
172176
if is_exclude_file(file_path, prev_dir, prev_dir_value):
173177
result_item.exclude = True
174178
scancode_file_item.append(result_item)
@@ -269,6 +273,10 @@ def parsing_scancode_32_later(
269273

270274
result_item.exclude = is_exclude_file(file_path)
271275
result_item.is_license_text = file.get("percentage_of_license_text", 0) > 90 or is_notice_file(file_path)
276+
277+
if is_manifest_file(file_path) and len(license_detected) > 0:
278+
result_item.is_license_text = True
279+
272280
scancode_file_item.append(result_item)
273281
except Exception as ex:
274282
msg.append(f"Error Parsing item: {ex}")

src/fosslight_source/_scan_item.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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 = [r'.*\.pom$', r'package\.json$', r'setup\.py$', r'pubspec\.yaml$', r'.*\.podspec$', r'Cargo\.toml$']
1718
_exclude_filename = ["changelog", "config.guess", "config.sub", "changes", "ltmain.sh",
1819
"configure", "configure.ac", "depcomp", "compile", "missing", "makefile"]
1920
_exclude_extension = [".m4", ".in", ".po"]
@@ -137,6 +138,11 @@ def is_exclude_file(file_path: str, prev_dir: str = None, prev_dir_exclude_value
137138

138139
def is_notice_file(file_path: str) -> bool:
139140
pattern = r"({})(?<!w)".format("|".join(_notice_filename))
140-
file_path = file_path.lower()
141141
filename = os.path.basename(file_path)
142-
return bool(re.match(pattern, filename))
142+
return bool(re.match(pattern, filename, re.IGNORECASE))
143+
144+
145+
def is_manifest_file(file_path: str) -> bool:
146+
pattern = r"({})$".format("|".join(_manifest_filename))
147+
filename = os.path.basename(file_path)
148+
return bool(re.match(pattern, filename, re.IGNORECASE))

0 commit comments

Comments
 (0)