2020-08-14 10:25:48 +00:00
|
|
|
# MIT licensed
|
2024-06-01 08:34:36 +00:00
|
|
|
# Copyright (c) 2013-2021,2023-2024 lilydjwg <lilydjwg@gmail.com>, et al.
|
2020-08-14 10:25:48 +00:00
|
|
|
|
2024-06-01 08:34:36 +00:00
|
|
|
import structlog
|
|
|
|
from packaging.version import Version, InvalidVersion
|
2020-08-14 10:25:48 +00:00
|
|
|
|
2023-10-14 06:51:15 +00:00
|
|
|
from nvchecker.api import RichResult
|
|
|
|
|
2024-06-01 08:34:36 +00:00
|
|
|
logger = structlog.get_logger(logger_name=__name__)
|
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
2024-05-19 04:10:40 +00:00
|
|
|
ret = []
|
|
|
|
|
2020-08-14 10:25:48 +00:00
|
|
|
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)
|
|
|
|
|
2024-05-19 04:10:40 +00:00
|
|
|
for version in data['releases'].keys():
|
2024-06-01 08:34:36 +00:00
|
|
|
try:
|
|
|
|
parsed_version = Version(version)
|
|
|
|
except InvalidVersion:
|
|
|
|
if data['releases'][version]:
|
|
|
|
# emit a warning if there is something under the invalid version
|
|
|
|
# sympy has an empty "0.5.13-hg" version
|
|
|
|
logger.warning('ignoring invalid version', version=version)
|
|
|
|
continue
|
2024-05-19 04:10:40 +00:00
|
|
|
|
|
|
|
if not use_pre_release and parsed_version.is_prerelease:
|
|
|
|
continue
|
|
|
|
|
|
|
|
ret.append(RichResult(
|
|
|
|
version = version,
|
|
|
|
url = f'https://pypi.org/project/{package}/{version}/',
|
|
|
|
))
|
|
|
|
|
|
|
|
return ret
|