Skip to content

Commit 882aa6f

Browse files
committed
Remove the oss name checking with url
Signed-off-by: Jiyeong Seok <[email protected]>
1 parent 8f61441 commit 882aa6f

File tree

3 files changed

+7
-100
lines changed

3 files changed

+7
-100
lines changed

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ fosslight_util>=1.4.32
88
fosslight_source>=1.7.3
99
fosslight_dependency>=3.7.4
1010
fosslight_binary>=4.1.24
11-
fosslight_prechecker>=3.0.1
12-
npm
13-
requests
11+
fosslight_prechecker>=3.0.1

src/fosslight_scanner/common.py

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
import sys
88
import logging
99
import shutil
10-
import re
1110
import pandas as pd
1211
import yaml
1312
import copy
14-
import requests
15-
from npm.bindings import npm_run
16-
from lastversion import latest
1713
import fosslight_util.constant as constant
1814
from fosslight_util.parsing_yaml import parsing_yml
1915
from fosslight_util.write_yaml import create_yaml_with_ossitem
@@ -93,94 +89,6 @@ def call_analysis_api(path_to_run, str_run_start, return_idx, func, *args):
9389
return success, result
9490

9591

96-
def extract_name_version_from_link(link):
97-
# Github : https://github.com/(owner)/(repo)
98-
# npm : https://www.npmjs.com/package/(package)/v/(version)
99-
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
100-
# pypi : https://pypi.org/project/(oss_name)/(version)
101-
# pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
102-
# Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
103-
# pub: https://pub.dev/packages/(package)/versions/(version)
104-
# Cocoapods: https://cocoapods.org/(package)
105-
pkg_pattern = {
106-
"github": r'https?:\/\/github.com\/([^\/]+)\/([^\/\.]+)(\.git)?',
107-
"pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
108-
"pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
109-
"maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
110-
"npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
111-
"npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
112-
"pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
113-
"pods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)'
114-
}
115-
oss_name = ""
116-
oss_version = ""
117-
if link.startswith("www."):
118-
link = link.replace("www.", "https://www.", 1)
119-
for key, value in pkg_pattern.items():
120-
p = re.compile(value)
121-
match = p.match(link)
122-
if match:
123-
try:
124-
origin_name = match.group(1)
125-
if key == "github":
126-
repo = match.group(2)
127-
oss_name = f"{origin_name}-{repo}"
128-
elif (key == "pypi") or (key == "pypi2"):
129-
oss_name = f"pypi:{origin_name}"
130-
oss_name = re.sub(r"[-_.]+", "-", oss_name).lower()
131-
oss_version = match.group(2)
132-
elif key == "maven":
133-
artifact = match.group(2)
134-
oss_name = f"{origin_name}:{artifact}"
135-
origin_name = oss_name
136-
oss_version = match.group(3)
137-
elif key == "npm" or key == "npm2":
138-
oss_name = f"npm:{origin_name}"
139-
oss_version = match.group(2)
140-
elif key == "pub":
141-
oss_name = f"pub:{origin_name}"
142-
oss_version = match.group(2)
143-
elif key == "pods":
144-
oss_name = f"cocoapods:{origin_name}"
145-
except Exception as ex:
146-
logger.info(f"extract_name_version_from_link {key}:{ex}")
147-
if oss_name and (not oss_version):
148-
if key in ["pypi", "maven", "npm", "npm2", "pub"]:
149-
oss_version, link = get_latest_package_version(link, key, origin_name)
150-
logger.debug(f'Try to download with the latest version:{link}')
151-
break
152-
return oss_name, oss_version, link
153-
154-
155-
def get_latest_package_version(link, pkg_type, oss_name):
156-
find_version = ''
157-
link_with_version = link
158-
159-
try:
160-
if pkg_type in ['npm', 'npm2']:
161-
stderr, stdout = npm_run('view', oss_name, 'version')
162-
if stdout:
163-
find_version = stdout.strip()
164-
link_with_version = f'https://www.npmjs.com/package/{oss_name}/v/{find_version}'
165-
elif pkg_type == 'pypi':
166-
find_version = str(latest(oss_name, at='pip', output_format='version', pre_ok=True))
167-
link_with_version = f'https://pypi.org/project/{oss_name}/{find_version}'
168-
elif pkg_type == 'maven':
169-
maven_response = requests.get(f'https://api.deps.dev/v3alpha/systems/maven/packages/{oss_name}')
170-
if maven_response.status_code == 200:
171-
find_version = maven_response.json().get('versions')[-1].get('versionKey').get('version')
172-
oss_name = oss_name.replace(':', '/')
173-
link_with_version = f'https://mvnrepository.com/artifact/{oss_name}/{find_version}'
174-
elif pkg_type == 'pub':
175-
pub_response = requests.get(f'https://pub.dev/api/packages/{oss_name}')
176-
if pub_response.status_code == 200:
177-
find_version = pub_response.json().get('latest').get('version')
178-
link_with_version = f'https://pub.dev/packages/{oss_name}/versions/{find_version}'
179-
except Exception as e:
180-
logger.debug(f'Fail to get latest package version({link}:{e})')
181-
return find_version, link_with_version
182-
183-
18492
def overwrite_excel(excel_file_path, oss_name, column_name='OSS Name'):
18593
if oss_name != "":
18694
try:

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from fosslight_util.output_format import check_output_format
2424
from fosslight_prechecker._precheck import run_lint as prechecker_lint
2525
from .common import (copy_file, call_analysis_api,
26-
overwrite_excel, extract_name_version_from_link,
26+
overwrite_excel,
2727
merge_yamls, correct_scanner_result,
2828
create_scancodejson)
2929
from fosslight_util.write_excel import merge_excels
@@ -255,14 +255,16 @@ def download_source(link, out_dir):
255255
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
256256
success = False
257257
temp_src_dir = ""
258+
oss_name = ""
259+
oss_version = ""
258260
try:
259261
success, final_excel_dir, result_log = init(out_dir)
260262
temp_src_dir = os.path.join(
261263
_output_dir, SRC_DIR_FROM_LINK_PREFIX + start_time)
262264

263265
link = link.strip()
264266
logger.info(f"Link to download: {link}")
265-
success, msg = cli_download_and_extract(
267+
success, msg, oss_name, oss_version = cli_download_and_extract(
266268
link, temp_src_dir, _output_dir)
267269

268270
if success:
@@ -273,7 +275,7 @@ def download_source(link, out_dir):
273275
except Exception as ex:
274276
success = False
275277
logger.error(f"Failed to analyze from link: {ex}")
276-
return success, temp_src_dir
278+
return success, temp_src_dir, oss_name, oss_version
277279

278280

279281
def init(output_path="", make_outdir=True):
@@ -394,8 +396,7 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
394396

395397
if url_to_analyze != "":
396398
remove_downloaded_source = True
397-
default_oss_name, default_oss_version, url_to_analyze = extract_name_version_from_link(url_to_analyze)
398-
success, src_path = download_source(url_to_analyze, output_path)
399+
success, src_path, default_oss_name, default_oss_version = download_source(url_to_analyze, output_path)
399400

400401
if output_extension == ".yaml":
401402
correct_mode = False

0 commit comments

Comments
 (0)