Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
Show All 38 Lines | |||||
class NixGuixPackageInfo(BasePackageInfo): | 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], version: str | |||||
) -> "NixGuixPackageInfo": | |||||
return cls( | return cls( | ||||
url=metadata["url"], | url=metadata["url"], | ||||
filename=None, | filename=None, | ||||
version=version, | |||||
integrity=metadata["integrity"], | integrity=metadata["integrity"], | ||||
raw_info=metadata, | 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")) | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | class NixGuixLoader(PackageLoader[NixGuixPackageInfo]): | ||||
# Note: this could be renamed get_artifact_info in the PackageLoader | # Note: this could be renamed get_artifact_info in the PackageLoader | ||||
# base class. | # base class. | ||||
def get_package_info(self, url) -> Iterator[Tuple[str, NixGuixPackageInfo]]: | def get_package_info(self, url) -> Iterator[Tuple[str, NixGuixPackageInfo]]: | ||||
# TODO: try all mirrors and not only the first one. A source | # TODO: try all mirrors and not only the first one. A source | ||||
# can be fetched from several urls, called mirrors. We | # can be fetched from several urls, called mirrors. We | ||||
# currently only use the first one, but if the first one | # currently only use the first one, but if the first one | ||||
# fails, we should try the second one and so on. | # fails, we should try the second one and so on. | ||||
integrity = self.integrity_by_url()[url] | integrity = self.integrity_by_url()[url] | ||||
p_info = NixGuixPackageInfo.from_metadata({"url": url, "integrity": integrity}) | p_info = NixGuixPackageInfo.from_metadata( | ||||
{"url": url, "integrity": integrity}, version=url | |||||
) | |||||
yield url, p_info | yield url, p_info | ||||
def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | ||||
"""We add a branch to the snapshot called 'evaluation' pointing to the | """We add a branch to the snapshot called 'evaluation' pointing to the | ||||
revision used to generate the sources.json file. This revision | revision used to generate the sources.json file. This revision | ||||
is specified in the sources.json file itself. For the nixpkgs | is specified in the sources.json file itself. For the nixpkgs | ||||
origin, this revision is coming from the | origin, this revision is coming from the | ||||
github.com/nixos/nixpkgs repository. | github.com/nixos/nixpkgs repository. | ||||
Show All 14 Lines | def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | ||||
return { | return { | ||||
b"evaluation": { | b"evaluation": { | ||||
"target_type": "revision", | "target_type": "revision", | ||||
"target": hashutil.hash_to_bytes(revision), | "target": hashutil.hash_to_bytes(revision), | ||||
} | } | ||||
} | } | ||||
def build_release( | def build_release( | ||||
self, | self, p_info: NixGuixPackageInfo, uncompressed_path: str, directory: Sha1Git | ||||
version: str, | |||||
p_info: NixGuixPackageInfo, | |||||
uncompressed_path: str, | |||||
directory: Sha1Git, | |||||
) -> Optional[Release]: | ) -> Optional[Release]: | ||||
return Release( | return Release( | ||||
name=version.encode(), | name=p_info.version.encode(), | ||||
message=b"", | message=b"", | ||||
author=EMPTY_AUTHOR, | author=EMPTY_AUTHOR, | ||||
date=None, | date=None, | ||||
target=directory, | target=directory, | ||||
target_type=ObjectType.DIRECTORY, | target_type=ObjectType.DIRECTORY, | ||||
synthetic=True, | synthetic=True, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |