mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
add CRAN support
add CRAN support using https://cran.r-project.org/src/contrib/PACKAGES
This commit is contained in:
parent
8db5c6a938
commit
4628315ba6
3 changed files with 47 additions and 0 deletions
|
@ -506,6 +506,17 @@ Check `MetaCPAN <https://metacpan.org/>`_ for updates.
|
|||
cpan
|
||||
The name used on CPAN, e.g. ``YAML``.
|
||||
|
||||
Check CRAN
|
||||
~~~~~~~~~~
|
||||
::
|
||||
|
||||
source = "cran"
|
||||
|
||||
Check `CRAN <https://cran.r-project.org/>`_ for updates.
|
||||
|
||||
cran
|
||||
The name used on CRAN, e.g. ``ggplot2``.
|
||||
|
||||
Check Packagist
|
||||
~~~~~~~~~~~~~~~
|
||||
::
|
||||
|
|
25
nvchecker_source/cran.py
Normal file
25
nvchecker_source/cran.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2021- hubutui <hot123tea123@gmail.com>
|
||||
import configparser
|
||||
|
||||
from nvchecker.api import session
|
||||
|
||||
CRAN_URL = 'https://cran.r-project.org/src/contrib/PACKAGES'
|
||||
|
||||
async def get_versions(url: str):
|
||||
result = {}
|
||||
res = await session.get(url)
|
||||
config = configparser.ConfigParser()
|
||||
for item in res.body.decode("UTF-8").split("\n\n"):
|
||||
if item.startswith("Package: "):
|
||||
rpkgname = item.split('\n')[0].replace(' ', '').split(':')[1]
|
||||
config.read_string(f"[{rpkgname}]\n" + item)
|
||||
result[rpkgname] = config[rpkgname]["version"]
|
||||
|
||||
return result
|
||||
|
||||
async def get_version(name, conf, *, cache, **kwargs):
|
||||
rpkgname = conf.get('cran', name)
|
||||
versions = await cache.get(CRAN_URL, get_versions)
|
||||
|
||||
return versions[rpkgname]
|
11
tests/test_cran.py
Normal file
11
tests/test_cran.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2021- hubutui <hot123tea123@gmail.com>
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]
|
||||
|
||||
async def test_cran(get_version):
|
||||
assert await get_version("ggplot2", {
|
||||
"source": "cran",
|
||||
}) == "3.3.3"
|
Loading…
Add table
Reference in a new issue