2020-08-14 10:25:48 +00:00
|
|
|
# MIT licensed
|
2021-01-15 07:40:23 +00:00
|
|
|
# Copyright (c) 2013-2021 lilydjwg <lilydjwg@gmail.com>, et al.
|
2020-08-14 10:25:48 +00:00
|
|
|
|
2021-01-15 07:40:23 +00:00
|
|
|
from packaging.version import Version
|
2020-08-14 10:25:48 +00:00
|
|
|
|
2023-10-14 06:51:15 +00:00
|
|
|
from nvchecker.api import RichResult
|
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
|
|
|
package = conf.get('pypi') or name
|
|
|
|
use_pre_release = conf.get('use_pre_release', False)
|
|
|
|
|
|
|
|
url = 'https://pypi.org/pypi/{}/json'.format(package)
|
|
|
|
|
|
|
|
data = await cache.get_json(url)
|
|
|
|
|
|
|
|
if use_pre_release:
|
|
|
|
version = sorted(
|
|
|
|
data['releases'].keys(),
|
2021-01-15 07:40:23 +00:00
|
|
|
key = Version,
|
2020-08-14 10:25:48 +00:00
|
|
|
)[-1]
|
|
|
|
else:
|
|
|
|
version = data['info']['version']
|
2023-10-14 06:51:15 +00:00
|
|
|
return RichResult(
|
|
|
|
version = version,
|
|
|
|
url = f'https://pypi.org/project/{package}/{version}/',
|
|
|
|
)
|