fosslight-util 2.1.25__py3-none-any.whl → 2.1.26__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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 2.1.25
3
+ Version: 2.1.26
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
@@ -1,5 +1,5 @@
1
1
  fosslight_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_util/_get_downloadable_url.py,sha256=zCBSVNTEumVxeLyaW5l4HKYKt73NLbC2y7gZoAhuWYA,14618
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
@@ -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.25.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
- fosslight_util-2.1.25.dist-info/METADATA,sha256=0b0HGakU9LVL793HbmKJv5bR_iCtOdHtG8DPx8JIdeM,6156
29
- fosslight_util-2.1.25.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
30
- fosslight_util-2.1.25.dist-info/entry_points.txt,sha256=0yZggRWNwDaClDG8UmUA10UFG8cVX3Jiy5gG9nW7hJs,68
31
- fosslight_util-2.1.25.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
32
- fosslight_util-2.1.25.dist-info/RECORD,,
27
+ fosslight_util-2.1.26.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
+ fosslight_util-2.1.26.dist-info/METADATA,sha256=1lVpJ2_RFRsVWyNc2xScsysx68BRHpYDEehnOXjTJnQ,6156
29
+ fosslight_util-2.1.26.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
30
+ fosslight_util-2.1.26.dist-info/entry_points.txt,sha256=0yZggRWNwDaClDG8UmUA10UFG8cVX3Jiy5gG9nW7hJs,68
31
+ fosslight_util-2.1.26.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
32
+ fosslight_util-2.1.26.dist-info/RECORD,,