Skip to content

Commit da7ba22

Browse files
authored
Merge pull request #214 from fosslight/exclude
Exclude package dirs with directory name
2 parents 6cded1f + 6bedf14 commit da7ba22

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ PyYAML
66
wheel>=0.38.1
77
intbitset
88
fosslight_binary>=5.0.0
9-
scancode-toolkit>=32.0.2
9+
scancode-toolkit>=32.0.2
10+
fingerprints==1.2.3
11+
normality==2.6.1

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._scan_item import replace_word
1515
from ._scan_item import is_notice_file
1616
from ._scan_item import is_manifest_file
17+
from ._scan_item import is_package_dir
1718
from typing import Tuple
1819

1920
logger = logging.getLogger(constant.LOGGER_NAME)
@@ -99,6 +100,13 @@ def parsing_scancode_32_earlier(scancode_file_list: list, has_error: bool = Fals
99100
copyright_list = file.get("copyrights", [])
100101

101102
result_item = SourceItem(file_path)
103+
is_pkg, pkg_path = is_package_dir(os.path.dirname(file_path))
104+
if is_pkg:
105+
result_item.source_name_or_path = pkg_path
106+
if not any(x.source_name_or_path == result_item.source_name_or_path for x in scancode_file_item):
107+
result_item.exclude = True
108+
scancode_file_item.append(result_item)
109+
continue
102110

103111
if has_error and "scan_errors" in file:
104112
error_msg = file.get("scan_errors", [])
@@ -235,6 +243,13 @@ def parsing_scancode_32_later(
235243
continue
236244

237245
result_item = SourceItem(file_path)
246+
is_pkg, pkg_path = is_package_dir(os.path.dirname(file_path))
247+
if is_pkg:
248+
result_item.source_name_or_path = pkg_path
249+
if not any(x.source_name_or_path == result_item.source_name_or_path for x in scancode_file_item):
250+
result_item.exclude = True
251+
scancode_file_item.append(result_item)
252+
continue
238253

239254
if has_error:
240255
error_msg = file.get("scan_errors", [])

src/fosslight_source/_parsing_scanoss_file.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import fosslight_util.constant as constant
99
from ._scan_item import SourceItem
1010
from ._scan_item import is_exclude_file
11+
from ._scan_item import is_package_dir
1112
from ._scan_item import replace_word
1213
from typing import Tuple
1314

@@ -45,6 +46,13 @@ def parsing_scanResult(scanoss_report: dict, path_to_scan: str = "", path_to_exc
4546
if any(os.path.commonpath([abs_file_path, exclude_path]) == exclude_path for exclude_path in abs_path_to_exclude):
4647
continue
4748
result_item = SourceItem(file_path)
49+
is_pkg, pkg_path = is_package_dir(os.path.dirname(file_path))
50+
if is_pkg:
51+
result_item.source_name_or_path = pkg_path
52+
if not any(x.source_name_or_path == result_item.source_name_or_path for x in scanoss_file_item):
53+
result_item.exclude = True
54+
scanoss_file_item.append(result_item)
55+
continue
4856

4957
if 'id' in findings[0]:
5058
if "none" == findings[0]['id']:

src/fosslight_source/_scan_item.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
_exclude_directory = [os.path.sep + dir_name +
2323
os.path.sep for dir_name in _exclude_directory]
2424
_exclude_directory.append("/.")
25+
_package_directory = ["node_modules", "venv", "Pods", "Carthage"]
2526
MAX_LICENSE_LENGTH = 200
2627
MAX_LICENSE_TOTAL_LENGTH = 600
2728
SUBSTRING_LICENSE_COMMENT = "Maximum character limit (License)"
@@ -146,3 +147,13 @@ def is_manifest_file(file_path: str) -> bool:
146147
pattern = r"({})$".format("|".join(_manifest_filename))
147148
filename = os.path.basename(file_path)
148149
return bool(re.match(pattern, filename, re.IGNORECASE))
150+
151+
152+
def is_package_dir(dir_path: str) -> bool:
153+
path_parts = dir_path.split(os.path.sep)
154+
for pkg_dir in _package_directory:
155+
if pkg_dir in path_parts:
156+
pkg_index = path_parts.index(pkg_dir)
157+
pkg_path = os.path.sep.join(path_parts[:pkg_index + 1])
158+
return True, pkg_path
159+
return False, ""

src/fosslight_source/run_scancode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def run_scan(
127127
result_list, key=lambda row: (''.join(row.licenses)))
128128

129129
for scan_item in result_list:
130+
if os.path.isdir(scan_item.source_name_or_path):
131+
continue
130132
if check_binary(os.path.join(path_to_scan, scan_item.source_name_or_path)):
131133
scan_item.exclude = True
132134
except Exception as ex:

0 commit comments

Comments
 (0)