MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / fetch_latest_version

Function fetch_latest_version

src/scancode/outdated.py:221–250  ·  view source on GitHub ↗

Fetch `new_version_url` and return the latest version of scancode as a string.

(new_version_url='https://pypi.org/pypi/scancode-toolkit/json')

Source from the content-addressed store, hash-verified

219
220
221def fetch_latest_version(new_version_url='https://pypi.org/pypi/scancode-toolkit/json'):
222 """
223 Fetch `new_version_url` and return the latest version of scancode as a
224 string.
225 """
226 requests_args = dict(
227 timeout=10,
228 verify=True,
229 headers={'Accept': 'application/json'},
230 )
231 try:
232 response = requests.get(new_version_url, **requests_args)
233 except (ConnectionError) as e:
234 logger.debug('fetch_latest_version: Download failed for %(url)r' % locals())
235 raise
236
237 status = response.status_code
238 if status != 200:
239 msg = 'fetch_latest_version: Download failed for %(url)r with %(status)r' % locals()
240 logger.debug(msg)
241 raise Exception(msg)
242
243 # The check is done using python.org PyPI API
244 payload = response.json()
245 releases = [
246 r for r in payload['releases'] if not packaging_version.parse(r).is_prerelease]
247 releases = sorted(releases, key=packaging_version.parse)
248 latest_version = releases[-1]
249
250 return latest_version

Callers 1

fetch_newer_versionFunction · 0.85

Calls 3

getMethod · 0.65
debugMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected