Enable black
- blackify all the python files, - enable black in pre-commit, - add a black tox environment.
This commit is contained in:
parent
1ae75166c7
commit
93a4d8b784
97 changed files with 1734 additions and 1642 deletions
|
@ -7,7 +7,8 @@ def register():
|
|||
from .models import PyPIModel
|
||||
from .lister import PyPILister
|
||||
|
||||
return {'models': [PyPIModel],
|
||||
'lister': PyPILister,
|
||||
'task_modules': ['%s.tasks' % __name__],
|
||||
}
|
||||
return {
|
||||
"models": [PyPIModel],
|
||||
"lister": PyPILister,
|
||||
"task_modules": ["%s.tasks" % __name__],
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ from requests import Response
|
|||
|
||||
class PyPILister(ListerOnePageApiTransport, SimpleLister):
|
||||
MODEL = PyPIModel
|
||||
LISTER_NAME = 'pypi'
|
||||
PAGE = 'https://pypi.org/simple/'
|
||||
instance = 'pypi' # As of today only the main pypi.org is used
|
||||
LISTER_NAME = "pypi"
|
||||
PAGE = "https://pypi.org/simple/"
|
||||
instance = "pypi" # As of today only the main pypi.org is used
|
||||
|
||||
def __init__(self, override_config=None):
|
||||
ListerOnePageApiTransport .__init__(self)
|
||||
ListerOnePageApiTransport.__init__(self)
|
||||
SimpleLister.__init__(self, override_config=override_config)
|
||||
|
||||
def task_dict(self, origin_type: str, origin_url: str, **kwargs):
|
||||
|
@ -33,17 +33,16 @@ class PyPILister(ListerOnePageApiTransport, SimpleLister):
|
|||
needed for the ingestion task creation.
|
||||
|
||||
"""
|
||||
_type = 'load-%s' % origin_type
|
||||
_policy = kwargs.get('policy', 'recurring')
|
||||
return utils.create_task_dict(
|
||||
_type, _policy, url=origin_url)
|
||||
_type = "load-%s" % origin_type
|
||||
_policy = kwargs.get("policy", "recurring")
|
||||
return utils.create_task_dict(_type, _policy, url=origin_url)
|
||||
|
||||
def list_packages(self, response: Response) -> list:
|
||||
"""(Override) List the actual pypi origins from the response.
|
||||
|
||||
"""
|
||||
result = xmltodict.parse(response.content)
|
||||
_packages = [p['#text'] for p in result['html']['body']['a']]
|
||||
_packages = [p["#text"] for p in result["html"]["body"]["a"]]
|
||||
random.shuffle(_packages)
|
||||
return _packages
|
||||
|
||||
|
@ -51,7 +50,7 @@ class PyPILister(ListerOnePageApiTransport, SimpleLister):
|
|||
"""Returns origin_url
|
||||
|
||||
"""
|
||||
return 'https://pypi.org/project/%s/' % repo_name
|
||||
return "https://pypi.org/project/%s/" % repo_name
|
||||
|
||||
def get_model_from_repo(self, repo_name: str) -> Dict[str, Any]:
|
||||
"""(Override) Transform from repository representation to model
|
||||
|
@ -59,10 +58,10 @@ class PyPILister(ListerOnePageApiTransport, SimpleLister):
|
|||
"""
|
||||
origin_url = self.origin_url(repo_name)
|
||||
return {
|
||||
'uid': origin_url,
|
||||
'name': repo_name,
|
||||
'full_name': repo_name,
|
||||
'html_url': origin_url,
|
||||
'origin_url': origin_url,
|
||||
'origin_type': 'pypi',
|
||||
"uid": origin_url,
|
||||
"name": repo_name,
|
||||
"full_name": repo_name,
|
||||
"html_url": origin_url,
|
||||
"origin_url": origin_url,
|
||||
"origin_type": "pypi",
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ class PyPIModel(ModelBase):
|
|||
"""a PyPI repository representation
|
||||
|
||||
"""
|
||||
__tablename__ = 'pypi_repo'
|
||||
|
||||
__tablename__ = "pypi_repo"
|
||||
|
||||
uid = Column(String, primary_key=True)
|
||||
|
|
|
@ -7,12 +7,12 @@ from celery import shared_task
|
|||
from .lister import PyPILister
|
||||
|
||||
|
||||
@shared_task(name=__name__ + '.PyPIListerTask')
|
||||
@shared_task(name=__name__ + ".PyPIListerTask")
|
||||
def list_pypi(**lister_args):
|
||||
'Full update of the PyPI (python) registry'
|
||||
"Full update of the PyPI (python) registry"
|
||||
return PyPILister(**lister_args).run()
|
||||
|
||||
|
||||
@shared_task(name=__name__ + '.ping')
|
||||
@shared_task(name=__name__ + ".ping")
|
||||
def _ping():
|
||||
return 'OK'
|
||||
return "OK"
|
||||
|
|
|
@ -10,14 +10,16 @@ from swh.lister.core.tests.conftest import * # noqa
|
|||
|
||||
@pytest.fixture
|
||||
def lister_pypi(swh_listers):
|
||||
lister = swh_listers['pypi']
|
||||
lister = swh_listers["pypi"]
|
||||
|
||||
# Add the load-deb-package in the scheduler backend
|
||||
lister.scheduler.create_task_type({
|
||||
'type': 'load-pypi',
|
||||
'description': 'Load PyPI package',
|
||||
'backend_name': 'swh.loader.package.tasks.LoadPyPI',
|
||||
'default_interval': '1 day',
|
||||
})
|
||||
lister.scheduler.create_task_type(
|
||||
{
|
||||
"type": "load-pypi",
|
||||
"description": "Load PyPI package",
|
||||
"backend_name": "swh.loader.package.tasks.LoadPyPI",
|
||||
"default_interval": "1 day",
|
||||
}
|
||||
)
|
||||
|
||||
return lister
|
||||
|
|
|
@ -7,21 +7,21 @@
|
|||
def test_pypi_lister(lister_pypi, requests_mock_datadir):
|
||||
lister_pypi.run()
|
||||
|
||||
r = lister_pypi.scheduler.search_tasks(task_type='load-pypi')
|
||||
r = lister_pypi.scheduler.search_tasks(task_type="load-pypi")
|
||||
assert len(r) == 4
|
||||
|
||||
for row in r:
|
||||
assert row['type'] == 'load-pypi'
|
||||
assert row["type"] == "load-pypi"
|
||||
# arguments check
|
||||
args = row['arguments']['args']
|
||||
args = row["arguments"]["args"]
|
||||
assert len(args) == 0
|
||||
|
||||
# kwargs
|
||||
kwargs = row['arguments']['kwargs']
|
||||
kwargs = row["arguments"]["kwargs"]
|
||||
assert len(kwargs) == 1
|
||||
|
||||
origin_url = kwargs['url']
|
||||
assert 'https://pypi.org/project' in origin_url
|
||||
origin_url = kwargs["url"]
|
||||
assert "https://pypi.org/project" in origin_url
|
||||
|
||||
assert row['policy'] == 'recurring'
|
||||
assert row['priority'] is None
|
||||
assert row["policy"] == "recurring"
|
||||
assert row["priority"] is None
|
||||
|
|
|
@ -2,22 +2,20 @@ from unittest.mock import patch
|
|||
|
||||
|
||||
def test_ping(swh_app, celery_session_worker):
|
||||
res = swh_app.send_task(
|
||||
'swh.lister.pypi.tasks.ping')
|
||||
res = swh_app.send_task("swh.lister.pypi.tasks.ping")
|
||||
assert res
|
||||
res.wait()
|
||||
assert res.successful()
|
||||
assert res.result == 'OK'
|
||||
assert res.result == "OK"
|
||||
|
||||
|
||||
@patch('swh.lister.pypi.tasks.PyPILister')
|
||||
@patch("swh.lister.pypi.tasks.PyPILister")
|
||||
def test_lister(lister, swh_app, celery_session_worker):
|
||||
# setup the mocked PypiLister
|
||||
lister.return_value = lister
|
||||
lister.run.return_value = None
|
||||
|
||||
res = swh_app.send_task(
|
||||
'swh.lister.pypi.tasks.PyPIListerTask')
|
||||
res = swh_app.send_task("swh.lister.pypi.tasks.PyPIListerTask")
|
||||
assert res
|
||||
res.wait()
|
||||
assert res.successful()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue