fosslight-util 2.1.25__py3-none-any.whl → 2.1.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fosslight_util/_get_downloadable_url.py +74 -8
- fosslight_util/download.py +55 -10
- {fosslight_util-2.1.25.dist-info → fosslight_util-2.1.27.dist-info}/METADATA +1 -1
- {fosslight_util-2.1.25.dist-info → fosslight_util-2.1.27.dist-info}/RECORD +8 -8
- {fosslight_util-2.1.25.dist-info → fosslight_util-2.1.27.dist-info}/LICENSE +0 -0
- {fosslight_util-2.1.25.dist-info → fosslight_util-2.1.27.dist-info}/WHEEL +0 -0
- {fosslight_util-2.1.25.dist-info → fosslight_util-2.1.27.dist-info}/entry_points.txt +0 -0
- {fosslight_util-2.1.25.dist-info → fosslight_util-2.1.27.dist-info}/top_level.txt +0 -0
|
@@ -13,6 +13,43 @@ import fosslight_util.constant as constant
|
|
|
13
13
|
logger = logging.getLogger(constant.LOGGER_NAME)
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
def version_exists(pkg_type, origin_name, version):
|
|
17
|
+
try:
|
|
18
|
+
if pkg_type in ['npm', 'npm2']:
|
|
19
|
+
r = requests.get(f"https://registry.npmjs.org/{origin_name}", timeout=5)
|
|
20
|
+
if r.status_code == 200:
|
|
21
|
+
data = r.json()
|
|
22
|
+
return version in data.get('versions', {})
|
|
23
|
+
elif pkg_type == 'pypi':
|
|
24
|
+
r = requests.get(f"https://pypi.org/pypi/{origin_name}/{version}/json", timeout=5)
|
|
25
|
+
return r.status_code == 200
|
|
26
|
+
elif pkg_type == 'maven':
|
|
27
|
+
r = requests.get(f'https://api.deps.dev/v3alpha/systems/maven/packages/{origin_name}', timeout=5)
|
|
28
|
+
if r.status_code == 200:
|
|
29
|
+
versions = r.json().get('versions', [])
|
|
30
|
+
for vobj in versions:
|
|
31
|
+
vkey = vobj.get('versionKey') or {}
|
|
32
|
+
if vkey.get('version') == version:
|
|
33
|
+
return True
|
|
34
|
+
return False
|
|
35
|
+
elif pkg_type == 'pub':
|
|
36
|
+
r = requests.get(f'https://pub.dev/api/packages/{origin_name}', timeout=5)
|
|
37
|
+
if r.status_code == 200:
|
|
38
|
+
versions = r.json().get('versions', [])
|
|
39
|
+
return any(v.get('version') == version for v in versions if isinstance(v, dict))
|
|
40
|
+
elif pkg_type == 'go':
|
|
41
|
+
if not version.startswith('v'):
|
|
42
|
+
version = f'v{version}'
|
|
43
|
+
r = requests.get(f'https://proxy.golang.org/{origin_name}/@v/list', timeout=5)
|
|
44
|
+
if r.status_code == 200:
|
|
45
|
+
listed = r.text.splitlines()
|
|
46
|
+
return version in listed
|
|
47
|
+
except Exception as e:
|
|
48
|
+
logger.info(f'version_exists check failed ({pkg_type}:{origin_name}:{version}) {e}')
|
|
49
|
+
return True
|
|
50
|
+
return False
|
|
51
|
+
|
|
52
|
+
|
|
16
53
|
def extract_name_version_from_link(link, checkout_version):
|
|
17
54
|
oss_name = ""
|
|
18
55
|
oss_version = ""
|
|
@@ -52,14 +89,36 @@ def extract_name_version_from_link(link, checkout_version):
|
|
|
52
89
|
oss_version = match.group(2)
|
|
53
90
|
except Exception as ex:
|
|
54
91
|
logger.info(f"extract_name_version_from_link {key}:{ex}")
|
|
55
|
-
if oss_name
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
92
|
+
if oss_name:
|
|
93
|
+
# Priority: 1) detected oss_version 2) checkout_version 3) latest
|
|
94
|
+
need_latest = False
|
|
95
|
+
|
|
96
|
+
if not oss_version and checkout_version:
|
|
97
|
+
oss_version = checkout_version.strip()
|
|
98
|
+
if key in ["pypi", "maven", "npm", "npm2", "pub", "go"]:
|
|
99
|
+
if oss_version:
|
|
100
|
+
try:
|
|
101
|
+
if not version_exists(key, origin_name, oss_version):
|
|
102
|
+
logger.info(f'Version {oss_version} not found for {oss_name}; will attempt latest fallback')
|
|
103
|
+
need_latest = True
|
|
104
|
+
except Exception as e:
|
|
105
|
+
logger.info(f'Version validation failed ({oss_name}:{oss_version}) {e}; will attempt latest fallback')
|
|
106
|
+
need_latest = True
|
|
107
|
+
else:
|
|
108
|
+
need_latest = True
|
|
109
|
+
if need_latest:
|
|
110
|
+
latest_ver = get_latest_package_version(link, key, origin_name)
|
|
111
|
+
if latest_ver:
|
|
112
|
+
if oss_version and latest_ver != oss_version:
|
|
113
|
+
logger.info(f'Fallback to latest version {latest_ver} (previous invalid: {oss_version})')
|
|
114
|
+
elif not oss_version:
|
|
115
|
+
logger.info(f'Using latest version {latest_ver} (no version detected)')
|
|
116
|
+
oss_version = latest_ver
|
|
60
117
|
if oss_version:
|
|
61
|
-
|
|
62
|
-
|
|
118
|
+
try:
|
|
119
|
+
link = get_new_link_with_version(link, key, origin_name, oss_version)
|
|
120
|
+
except Exception as _e:
|
|
121
|
+
logger.info(f'Failed to build versioned link for {oss_name}:{oss_version} {_e}')
|
|
63
122
|
matched = True
|
|
64
123
|
break
|
|
65
124
|
if not matched:
|
|
@@ -78,6 +137,8 @@ def get_new_link_with_version(link, pkg_type, oss_name, oss_version):
|
|
|
78
137
|
elif pkg_type == "pub":
|
|
79
138
|
link = f'https://pub.dev/packages/{oss_name}/versions/{oss_version}'
|
|
80
139
|
elif pkg_type == "go":
|
|
140
|
+
if not oss_version.startswith('v'):
|
|
141
|
+
oss_version = f'v{oss_version}'
|
|
81
142
|
link = f'https://pkg.go.dev/{oss_name}@{oss_version}'
|
|
82
143
|
elif pkg_type == "cargo":
|
|
83
144
|
link = f'https://crates.io/crates/{oss_name}/{oss_version}'
|
|
@@ -97,7 +158,10 @@ def get_latest_package_version(link, pkg_type, oss_name):
|
|
|
97
158
|
elif pkg_type == 'maven':
|
|
98
159
|
maven_response = requests.get(f'https://api.deps.dev/v3alpha/systems/maven/packages/{oss_name}')
|
|
99
160
|
if maven_response.status_code == 200:
|
|
100
|
-
|
|
161
|
+
versions = maven_response.json().get('versions', [])
|
|
162
|
+
if versions:
|
|
163
|
+
cand = max(versions, key=lambda v: v.get('publishedAt', ''))
|
|
164
|
+
find_version = cand.get('versionKey', {}).get('version', '')
|
|
101
165
|
elif pkg_type == 'pub':
|
|
102
166
|
pub_response = requests.get(f'https://pub.dev/api/packages/{oss_name}')
|
|
103
167
|
if pub_response.status_code == 200:
|
|
@@ -106,6 +170,8 @@ def get_latest_package_version(link, pkg_type, oss_name):
|
|
|
106
170
|
go_response = requests.get(f'https://proxy.golang.org/{oss_name}/@latest')
|
|
107
171
|
if go_response.status_code == 200:
|
|
108
172
|
find_version = go_response.json().get('Version')
|
|
173
|
+
if find_version.startswith('v'):
|
|
174
|
+
find_version = find_version[1:]
|
|
109
175
|
except Exception as e:
|
|
110
176
|
logger.info(f'Fail to get latest package version({link}:{e})')
|
|
111
177
|
return find_version
|
fosslight_util/download.py
CHANGED
|
@@ -195,15 +195,60 @@ def get_ref_to_checkout(checkout_to, ref_list):
|
|
|
195
195
|
return ref_to_checkout
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
def
|
|
199
|
-
if
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
198
|
+
def get_remote_refs(git_url: str):
|
|
199
|
+
if not git_url:
|
|
200
|
+
return {"tags": [], "branches": []}
|
|
201
|
+
tags = []
|
|
202
|
+
branches = []
|
|
203
|
+
try:
|
|
204
|
+
cp = subprocess.run(["git", "ls-remote", "--tags", "--heads", git_url], capture_output=True, text=True, timeout=30)
|
|
205
|
+
if cp.returncode == 0:
|
|
206
|
+
for line in cp.stdout.splitlines():
|
|
207
|
+
parts = line.split('\t')
|
|
208
|
+
if len(parts) != 2:
|
|
209
|
+
continue
|
|
210
|
+
ref = parts[1]
|
|
211
|
+
if ref.startswith('refs/tags/'):
|
|
212
|
+
tags.append(ref[len('refs/tags/'):])
|
|
213
|
+
elif ref.startswith('refs/heads/'):
|
|
214
|
+
branches.append(ref[len('refs/heads/'):])
|
|
215
|
+
except Exception as e:
|
|
216
|
+
logger.debug(f"get_remote_refs - failed: {e}")
|
|
217
|
+
return {"tags": tags, "branches": branches}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def decide_checkout(checkout_to="", tag="", branch="", git_url=""):
|
|
221
|
+
base = checkout_to or tag or branch
|
|
222
|
+
if not base:
|
|
223
|
+
return ""
|
|
224
|
+
|
|
225
|
+
ref_dict = get_remote_refs(git_url)
|
|
226
|
+
tag_set = set(ref_dict.get("tags", []))
|
|
227
|
+
branch_set = set(ref_dict.get("branches", []))
|
|
228
|
+
|
|
229
|
+
ver_re = re.compile(r'^(?:v\.? ?)?' + re.escape(base) + r'$', re.IGNORECASE)
|
|
230
|
+
|
|
231
|
+
# tag: exact -> prefix variant -> endswith
|
|
232
|
+
if base in tag_set:
|
|
233
|
+
return base
|
|
234
|
+
tag_candidates = [c for c in tag_set if ver_re.match(c)]
|
|
235
|
+
if tag_candidates:
|
|
236
|
+
return min(tag_candidates, key=lambda x: (len(x), x.lower()))
|
|
237
|
+
tag_ends = [n for n in tag_set if n.endswith(base)]
|
|
238
|
+
if tag_ends:
|
|
239
|
+
return min(tag_ends, key=len)
|
|
240
|
+
|
|
241
|
+
# branch: exact -> prefix variant -> endswith
|
|
242
|
+
if base in branch_set:
|
|
243
|
+
return base
|
|
244
|
+
branch_candidates = [c for c in branch_set if ver_re.match(c)]
|
|
245
|
+
if branch_candidates:
|
|
246
|
+
return min(branch_candidates, key=lambda x: (len(x), x.lower()))
|
|
247
|
+
branch_ends = [n for n in branch_set if n.endswith(base)]
|
|
248
|
+
if branch_ends:
|
|
249
|
+
return min(branch_ends, key=len)
|
|
250
|
+
|
|
251
|
+
return base
|
|
207
252
|
|
|
208
253
|
|
|
209
254
|
def get_github_ossname(link):
|
|
@@ -263,7 +308,7 @@ def download_git_repository(refs_to_checkout, git_url, target_dir, tag, called_c
|
|
|
263
308
|
def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="",
|
|
264
309
|
ssh_key="", id="", git_token="", called_cli=True):
|
|
265
310
|
oss_name = get_github_ossname(git_url)
|
|
266
|
-
refs_to_checkout = decide_checkout(checkout_to, tag, branch)
|
|
311
|
+
refs_to_checkout = decide_checkout(checkout_to, tag, branch, git_url)
|
|
267
312
|
msg = ""
|
|
268
313
|
success = True
|
|
269
314
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
fosslight_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
fosslight_util/_get_downloadable_url.py,sha256=
|
|
2
|
+
fosslight_util/_get_downloadable_url.py,sha256=dvpre_cn3MoJBB2WgvqVbhdMpe3v2bEBywEdYaQqXjk,18007
|
|
3
3
|
fosslight_util/compare_yaml.py,sha256=eLqqCLgERxRHN5vsnpQVMXIEU862Lx66mD_y4uMgQE4,2916
|
|
4
4
|
fosslight_util/constant.py,sha256=zElnWOzXt020sYiFTiRQn8ZjZyZpL3aPmfAqfQLcxJk,2278
|
|
5
5
|
fosslight_util/correct.py,sha256=1WEAL-9_KhjFPLucPhv0PNN3K7avm0z8mU6sTuSyeHM,3864
|
|
6
6
|
fosslight_util/cover.py,sha256=qqqKzxqFwKimal764FaugRUBcHWdeKt8af6xeK0mH8E,2040
|
|
7
|
-
fosslight_util/download.py,sha256=
|
|
7
|
+
fosslight_util/download.py,sha256=t6-5NAcvCOfmi9TM7O1yp-9X11MiuKd8JdzNEZtEmqQ,20967
|
|
8
8
|
fosslight_util/exclude.py,sha256=fDmBsZJ_F7O9Oh2T-07R03XNbElo1tFaf_z01KfSAqU,2399
|
|
9
9
|
fosslight_util/help.py,sha256=iyWmAaUQSHJtWv5mjFv0f3YoDVlDgEqdsDDEyImEUNc,2646
|
|
10
10
|
fosslight_util/oss_item.py,sha256=8890JHb5ZoKQWAwN7Fl8badnlYatJtF4MVJz1rdS4yQ,6938
|
|
@@ -24,9 +24,9 @@ fosslight_util/write_yaml.py,sha256=QlEKoIPQsEaYERfbP53TeKgnllYzhLQWm5wYjnWtVjE,
|
|
|
24
24
|
fosslight_util/resources/frequentLicenselist.json,sha256=GUhzK6tu7ok10fekOnmVmUgIGRC-acGABZKTNKfDyYA,4776157
|
|
25
25
|
fosslight_util/resources/frequent_license_nick_list.json,sha256=ryU2C_6ZxHbz90_sUN9OvI9GXkCMLu7oGcmd9W79YYo,5005
|
|
26
26
|
fosslight_util/resources/licenses.json,sha256=mK55z-bhY7Mjpj2KsO1crKGGL-X3F6MBFQJ0zLlx010,240843
|
|
27
|
-
fosslight_util-2.1.
|
|
28
|
-
fosslight_util-2.1.
|
|
29
|
-
fosslight_util-2.1.
|
|
30
|
-
fosslight_util-2.1.
|
|
31
|
-
fosslight_util-2.1.
|
|
32
|
-
fosslight_util-2.1.
|
|
27
|
+
fosslight_util-2.1.27.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
28
|
+
fosslight_util-2.1.27.dist-info/METADATA,sha256=3qJSoRb1gzQpjjhlUSJU0msZ0o7y_BTNg1H7pCGUmwQ,6156
|
|
29
|
+
fosslight_util-2.1.27.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
30
|
+
fosslight_util-2.1.27.dist-info/entry_points.txt,sha256=0yZggRWNwDaClDG8UmUA10UFG8cVX3Jiy5gG9nW7hJs,68
|
|
31
|
+
fosslight_util-2.1.27.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
|
|
32
|
+
fosslight_util-2.1.27.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|