Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/npm/loader.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from codecs import BOM_UTF8 | from codecs import BOM_UTF8 | ||||
import json | import json | ||||
import logging | import logging | ||||
import os | import os | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | def __init__(self, url: str): | ||||
self.provider_url = f"https://replicate.npmjs.com/{safe_name}/" | self.provider_url = f"https://replicate.npmjs.com/{safe_name}/" | ||||
self._info: Dict[str, Any] = {} | self._info: Dict[str, Any] = {} | ||||
self._versions = None | self._versions = None | ||||
@cached_method | @cached_method | ||||
def _raw_info(self) -> bytes: | def _raw_info(self) -> bytes: | ||||
return api_info(self.provider_url) | return api_info(self.provider_url) | ||||
@cached_method | @cached_method | ||||
ardumont: That behavior may need to be pushed to the `api_info` function directly to avoid repetition. | |||||
def info(self) -> Dict: | def info(self) -> Dict: | ||||
"""Return the project metadata information (fetched from npm registry) | """Return the project metadata information (fetched from npm registry) | ||||
""" | """ | ||||
return json.loads(self._raw_info()) | return json.loads(self._raw_info()) | ||||
def get_versions(self) -> Sequence[str]: | def get_versions(self) -> Sequence[str]: | ||||
return sorted(list(self.info()["versions"].keys())) | return sorted(list(self.info()["versions"].keys())) | ||||
▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines |
That behavior may need to be pushed to the api_info function directly to avoid repetition.