fosslight-util 2.1.25__tar.gz → 2.1.27__tar.gz

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.
Files changed (39) hide show
  1. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/PKG-INFO +1 -1
  2. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/setup.py +1 -1
  3. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/_get_downloadable_url.py +74 -8
  4. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/download.py +55 -10
  5. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util.egg-info/PKG-INFO +1 -1
  6. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/LICENSE +0 -0
  7. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/MANIFEST.in +0 -0
  8. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/README.md +0 -0
  9. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/requirements.txt +0 -0
  10. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/setup.cfg +0 -0
  11. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/__init__.py +0 -0
  12. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/compare_yaml.py +0 -0
  13. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/constant.py +0 -0
  14. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/correct.py +0 -0
  15. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/cover.py +0 -0
  16. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/exclude.py +0 -0
  17. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/help.py +0 -0
  18. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/oss_item.py +0 -0
  19. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/output_format.py +0 -0
  20. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/parsing_yaml.py +0 -0
  21. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/read_excel.py +0 -0
  22. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  23. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  24. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/resources/licenses.json +0 -0
  25. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/set_log.py +0 -0
  26. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/spdx_licenses.py +0 -0
  27. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/timer_thread.py +0 -0
  28. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_cyclonedx.py +0 -0
  29. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_excel.py +0 -0
  30. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_opossum.py +0 -0
  31. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_scancodejson.py +0 -0
  32. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_spdx.py +0 -0
  33. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_txt.py +0 -0
  34. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util/write_yaml.py +0 -0
  35. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util.egg-info/SOURCES.txt +0 -0
  36. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  37. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  38. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util.egg-info/requires.txt +0 -0
  39. {fosslight_util-2.1.25 → fosslight_util-2.1.27}/src/fosslight_util.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight_util
3
- Version: 2.1.25
3
+ Version: 2.1.27
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Download-URL: https://github.com/fosslight/fosslight_util
@@ -14,7 +14,7 @@ with open('requirements.txt', 'r', 'utf-8') as f:
14
14
  if __name__ == "__main__":
15
15
  setup(
16
16
  name='fosslight_util',
17
- version='2.1.25',
17
+ version='2.1.27',
18
18
  package_dir={"": "src"},
19
19
  packages=find_packages(where='src'),
20
20
  description='FOSSLight Util',
@@ -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 and (not oss_version):
56
- if checkout_version:
57
- oss_version = checkout_version
58
- elif key in ["pypi", "maven", "npm", "npm2", "pub", "go"]:
59
- oss_version = get_latest_package_version(link, key, origin_name)
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
- link = get_new_link_with_version(link, key, origin_name, oss_version)
62
- logger.info(f'Try to download with the latest version:{link}')
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
- find_version = maven_response.json().get('versions')[-1].get('versionKey').get('version')
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
@@ -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 decide_checkout(checkout_to="", tag="", branch=""):
199
- if checkout_to:
200
- ref_to_checkout = checkout_to
201
- else:
202
- if branch:
203
- ref_to_checkout = branch
204
- else:
205
- ref_to_checkout = tag
206
- return ref_to_checkout
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 2.1.25
3
+ Version: 2.1.27
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Download-URL: https://github.com/fosslight/fosslight_util
File without changes