Skip to content

Commit 51845d3

Browse files
committed
Distinguish the origin of the pub package
Signed-off-by: jiyeong.seok <[email protected]>
1 parent a8d6963 commit 51845d3

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ defusedxml
1111
packageurl-python
1212
igraph
1313
matplotlib
14+
pyaskalono

src/fosslight_dependency/package_manager/Pub.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import shutil
1111
import yaml
1212
import subprocess
13+
from askalono import identify
1314
import fosslight_util.constant as constant
1415
import fosslight_dependency.constant as const
1516
from fosslight_dependency._package_manager import PackageManager
@@ -27,6 +28,7 @@ class Pub(PackageManager):
2728
input_file_name = 'tmp_flutter_oss_licenses.json'
2829
tmp_dir = "fl_dependency_tmp_dir"
2930
cur_path = ''
31+
pkg_source_list = {}
3032

3133
def __init__(self, input_dir, output_dir):
3234
super().__init__(self.package_manager_name, self.dn_url, input_dir, output_dir)
@@ -92,6 +94,7 @@ def parse_pub_deps_file(self, rel_json):
9294
if dep_key not in self.relation_tree:
9395
self.relation_tree[dep_key] = []
9496
self.relation_tree[dep_key].extend(p['dependencies'])
97+
self.pkg_source_list[dep_key] = p['source']
9598

9699
for i in self.relation_tree:
97100
tmp_dep = []
@@ -110,10 +113,9 @@ def parse_oss_information(self, f_name):
110113
with open(f_name, 'r', encoding='utf8') as pub_file:
111114
json_f = json.load(pub_file)
112115

113-
try:
114-
purl_dict = {}
115-
116-
for json_data in json_f:
116+
purl_dict = {}
117+
for json_data in json_f:
118+
try:
117119
dep_item = DependencyItem()
118120
oss_item = OssItem()
119121
oss_origin_name = json_data['name']
@@ -133,18 +135,9 @@ def parse_oss_information(self, f_name):
133135
purl_dict[f'{oss_origin_name}({oss_item.version})'] = dep_item.purl
134136
license_txt = json_data['license']
135137
if license_txt is not None:
136-
tmp_license_txt = open(tmp_license_txt_file_name, 'w', encoding='utf-8')
137-
tmp_license_txt.write(license_txt)
138-
tmp_license_txt.close()
139-
140-
license_name_with_license_scanner = check_and_run_license_scanner(self.platform,
141-
self.license_scanner_bin,
142-
tmp_license_txt_file_name)
143-
144-
if license_name_with_license_scanner != "":
145-
oss_item.license = license_name_with_license_scanner
146-
else:
147-
oss_item.license = ''
138+
detect_askalono = identify(license_txt)
139+
if detect_askalono.score > 0.7:
140+
oss_item.license = detect_askalono.name
148141

149142
if self.direct_dep:
150143
if oss_origin_name not in self.total_dep_list:
@@ -159,11 +152,20 @@ def parse_oss_information(self, f_name):
159152

160153
if f'{oss_origin_name}({oss_item.version})' in self.relation_tree:
161154
dep_item.depends_on_raw = self.relation_tree[f'{oss_origin_name}({oss_item.version})']
155+
if f'{oss_origin_name}({oss_item.version})' in self.pkg_source_list:
156+
pkg_source = self.pkg_source_list[f'{oss_origin_name}({oss_item.version})']
157+
if pkg_source in ['git', 'path']:
158+
oss_item.download_location = json_data['repository']
159+
if oss_item.download_location is None:
160+
oss_item.download_location = json_data['homepage']
161+
if oss_item.download_location is None:
162+
oss_item.download_location = ''
163+
oss_item.comment = pkg_source
162164

163165
dep_item.oss_items.append(oss_item)
164166
self.dep_items.append(dep_item)
165-
except Exception as e:
166-
logger.error(f"Fail to parse pub oss information: {e}")
167+
except Exception as e:
168+
logger.error(f"Fail to parse pub oss information: {e}")
167169
if self.direct_dep:
168170
self.dep_items = change_dependson_to_purl(purl_dict, self.dep_items)
169171

0 commit comments

Comments
 (0)