swh.lister.cran: Add description in task_dict
Add description in task_dict method because the only metadata that can be found for a package at CRAN is its decsription. That can only br achived from the build in API in R, which ister is already using. Hence instead of getting metadata in loader, it is passed by lister.
This commit is contained in:
parent
52b1de87c5
commit
5ea9d5ed39
2 changed files with 18 additions and 1 deletions
|
@ -5,6 +5,7 @@ import subprocess
|
|||
import json
|
||||
import logging
|
||||
import pkg_resources
|
||||
from collections import defaultdict
|
||||
|
||||
from swh.lister.cran.models import CRANModel
|
||||
|
||||
|
@ -17,6 +18,7 @@ class CRANLister(SimpleLister):
|
|||
MODEL = CRANModel
|
||||
LISTER_NAME = 'cran'
|
||||
instance = 'cran'
|
||||
descriptions = defaultdict(dict)
|
||||
|
||||
def task_dict(self, origin_type, origin_url, **kwargs):
|
||||
"""Return task format dict
|
||||
|
@ -26,7 +28,8 @@ class CRANLister(SimpleLister):
|
|||
"""
|
||||
return create_task_dict(
|
||||
'load-%s' % origin_type, 'recurring',
|
||||
kwargs.get('name'), origin_url, kwargs.get('version'))
|
||||
kwargs.get('name'), origin_url, kwargs.get('version'),
|
||||
project_metadata=self.descriptions[kwargs.get('name')])
|
||||
|
||||
def r_script_request(self):
|
||||
"""Runs R script which uses inbuilt API to return a json
|
||||
|
@ -65,6 +68,7 @@ class CRANLister(SimpleLister):
|
|||
"""Transform from repository representation to model
|
||||
|
||||
"""
|
||||
self.descriptions[repo["Package"]] = repo['Description']
|
||||
project_url = 'https://cran.r-project.org/src/contrib' \
|
||||
'/%(Package)s_%(Version)s.tar.gz' % repo
|
||||
return {
|
||||
|
|
13
swh/lister/cran/tests/test_lister.py
Normal file
13
swh/lister/cran/tests/test_lister.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from unittest.mock import patch
|
||||
from swh.lister.cran.lister import CRANLister
|
||||
|
||||
|
||||
def test_task_dict():
|
||||
lister = CRANLister()
|
||||
lister.descriptions['test_pack'] = 'Test Description'
|
||||
with patch('swh.lister.cran.lister.create_task_dict') as mock_create_tasks:
|
||||
lister.task_dict(origin_type='cran', origin_url='https://abc',
|
||||
name='test_pack')
|
||||
mock_create_tasks.assert_called_once_with(
|
||||
'load-cran', 'recurring', 'test_pack', 'https://abc', None,
|
||||
project_metadata='Test Description')
|
Loading…
Add table
Add a link
Reference in a new issue