Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/npm/loader.py
Show All 22 Lines | |||||
) | ) | ||||
from swh.loader.package.loader import PackageLoader | from swh.loader.package.loader import PackageLoader | ||||
from swh.loader.package.utils import api_info, release_name | from swh.loader.package.utils import api_info, release_name | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
vlorentz: Rename to `EMPTY_PERSON`, which I think is clearer? | |||||
Done Inline Actionsack ardumont: ack | |||||
DEFAULT_PERSON = Person(fullname=b"", name=None, email=None) | |||||
class NpmLoader(PackageLoader): | class NpmLoader(PackageLoader): | ||||
"""Load npm origin's artifact releases into swh archive. | """Load npm origin's artifact releases into swh archive. | ||||
""" | """ | ||||
visit_type = "npm" | visit_type = "npm" | ||||
def __init__(self, url: str): | def __init__(self, url: str): | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | |||||
def extract_npm_package_author(package_json: Dict[str, Any]) -> Person: | def extract_npm_package_author(package_json: Dict[str, Any]) -> Person: | ||||
""" | """ | ||||
Extract package author from a ``package.json`` file content and | Extract package author from a ``package.json`` file content and | ||||
return it in swh format. | return it in swh format. | ||||
Args: | Args: | ||||
package_json (dict): Dict holding the content of parsed | package_json: Dict holding the content of parsed | ||||
``package.json`` file | ``package.json`` file | ||||
Returns: | Returns: | ||||
Person | Person | ||||
""" | """ | ||||
for author_key in ("author", "authors"): | for author_key in ("author", "authors"): | ||||
if author_key in package_json: | if author_key in package_json: | ||||
author_str = _author_str(package_json[author_key]) | author_data = package_json[author_key] | ||||
if author_data is None: | |||||
return DEFAULT_PERSON | |||||
author_str = _author_str(author_data) | |||||
return Person.from_fullname(author_str.encode()) | return Person.from_fullname(author_str.encode()) | ||||
return Person(fullname=b"", name=None, email=None) | return DEFAULT_PERSON | ||||
def _lstrip_bom(s, bom=BOM_UTF8): | def _lstrip_bom(s, bom=BOM_UTF8): | ||||
if s.startswith(bom): | if s.startswith(bom): | ||||
return s[len(bom) :] | return s[len(bom) :] | ||||
else: | else: | ||||
return s | return s | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
Rename to EMPTY_PERSON, which I think is clearer?