Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
# Copyright (C) 2020-2021 The Software Heritage developers | # Copyright (C) 2020-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 | ||||
import copy | import copy | ||||
import json | import json | ||||
import logging | import logging | ||||
import re | import re | ||||
from typing import Any, Dict, Iterator, List, Mapping, Optional, Tuple | from typing import Any, Dict, Iterator, List, Mapping, Optional, Tuple | ||||
from urllib.parse import urlparse | |||||
import attr | import attr | ||||
from swh.loader.package.loader import ( | from swh.loader.package.loader import ( | ||||
BasePackageInfo, | BasePackageInfo, | ||||
PackageLoader, | PackageLoader, | ||||
PartialExtID, | PartialExtID, | ||||
RawExtrinsicMetadataCore, | RawExtrinsicMetadataCore, | ||||
Show All 24 Lines | class NixGuixPackageInfo(BasePackageInfo): | ||||
raw_info = attr.ib(type=Dict[str, Any]) | raw_info = attr.ib(type=Dict[str, Any]) | ||||
integrity = attr.ib(type=str) | integrity = attr.ib(type=str) | ||||
"""Hash of the archive, formatted as in the Subresource Integrity | """Hash of the archive, formatted as in the Subresource Integrity | ||||
specification.""" | specification.""" | ||||
@classmethod | @classmethod | ||||
def from_metadata(cls, metadata: Dict[str, Any]) -> "NixGuixPackageInfo": | def from_metadata(cls, metadata: Dict[str, Any]) -> "NixGuixPackageInfo": | ||||
url = metadata["url"] | |||||
if not urlparse(url).scheme: | |||||
olasd: Could this get a comment/pointer to the nix/guix specification where this fallback is defined? | |||||
KShivenduAuthorUnsubmitted Done Inline ActionsAre you talking about Package loader specifications, or something else? KShivendu: Are you talking about [Package loader specifications](https://docs.softwareheritage. | |||||
vlorentzUnsubmitted Not Done Inline Actionsdocumentation of Nix and/or Guix themselves, not documentation of Software Heritage vlorentz: documentation of Nix and/or Guix themselves, not documentation of Software Heritage | |||||
url = f"http://{url}" | |||||
return cls( | return cls( | ||||
url=metadata["url"], | url=url, filename=None, integrity=metadata["integrity"], raw_info=metadata, | ||||
filename=None, | |||||
integrity=metadata["integrity"], | |||||
raw_info=metadata, | |||||
) | ) | ||||
def extid(self) -> PartialExtID: | def extid(self) -> PartialExtID: | ||||
return (EXTID_TYPE, self.integrity.encode("ascii")) | return (EXTID_TYPE, self.integrity.encode("ascii")) | ||||
class NixGuixLoader(PackageLoader[NixGuixPackageInfo]): | class NixGuixLoader(PackageLoader[NixGuixPackageInfo]): | ||||
"""Load sources from a sources.json file. This loader is used to load | """Load sources from a sources.json file. This loader is used to load | ||||
▲ Show 20 Lines • Show All 248 Lines • Show Last 20 Lines |
Could this get a comment/pointer to the nix/guix specification where this fallback is defined?