2022-02-22 16:38:49 +00:00
|
|
|
# MIT licensed
|
|
|
|
# Copyright (c) 2022 Pekka Ristola <pekkarr [at] protonmail [dot] com>, et al.
|
|
|
|
|
2023-10-18 00:00:46 +00:00
|
|
|
from nvchecker.api import session, RichResult, GetVersionError
|
2022-02-22 16:38:49 +00:00
|
|
|
|
|
|
|
CRAN_URL = 'https://cran.r-project.org/package=%s/DESCRIPTION'
|
|
|
|
VERSION_FIELD = 'Version: '
|
|
|
|
|
|
|
|
async def request(pkg):
|
|
|
|
url = CRAN_URL % pkg
|
|
|
|
res = await session.get(url)
|
|
|
|
return res.body.decode('utf-8', errors='ignore')
|
|
|
|
|
|
|
|
async def get_version(name, conf, *, cache, **kwargs):
|
|
|
|
package = conf.get('cran', name)
|
|
|
|
|
|
|
|
desc = await cache.get(package, request)
|
|
|
|
|
|
|
|
for line in desc.splitlines():
|
|
|
|
if line.startswith(VERSION_FIELD):
|
|
|
|
version = line[len(VERSION_FIELD):]
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise GetVersionError('Invalid DESCRIPTION file')
|
|
|
|
|
2023-10-18 00:00:46 +00:00
|
|
|
return RichResult(
|
|
|
|
version = version,
|
|
|
|
url = f'https://cran.r-project.org/web/packages/{package}/',
|
|
|
|
)
|