Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | class NixGuixPackageInfo(BasePackageInfo): | ||||
def from_metadata(cls, metadata: Dict[str, Any]) -> "NixGuixPackageInfo": | def from_metadata(cls, metadata: Dict[str, Any]) -> "NixGuixPackageInfo": | ||||
return cls( | return cls( | ||||
url=metadata["url"], | url=metadata["url"], | ||||
filename=None, | filename=None, | ||||
integrity=metadata["integrity"], | integrity=metadata["integrity"], | ||||
raw_info=metadata, | raw_info=metadata, | ||||
) | ) | ||||
def extid(self) -> bytes: | |||||
return 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 | ||||
sources used by functional package manager (eg. Nix and Guix). | sources used by functional package manager (eg. Nix and Guix). | ||||
""" | """ | ||||
visit_type = "nixguix" | visit_type = "nixguix" | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | ) -> Dict[Sha1Git, Optional[ImmutableDict[str, object]]]: | ||||
ret = {} | ret = {} | ||||
for revision in known_revisions: | for revision in known_revisions: | ||||
if not revision: # revision_get can return None | if not revision: # revision_get can return None | ||||
continue | continue | ||||
ret[revision.id] = revision.metadata | ret[revision.id] = revision.metadata | ||||
return ret | return ret | ||||
def _get_integrity_from_artifact( | def known_artifact_to_extid(self, known_artifact: Dict) -> Optional[bytes]: | ||||
self, known_artifact: Dict, rev_id: bytes | |||||
) -> Optional[str]: | |||||
try: | try: | ||||
return known_artifact["extrinsic"]["raw"]["integrity"] | return known_artifact["extrinsic"]["raw"]["integrity"].encode("ascii") | ||||
except KeyError as e: | except KeyError as e: | ||||
logger.exception( | logger.exception( | ||||
"Unexpected metadata revision structure detected: %(context)s", | "Unexpected metadata revision structure detected: %(context)s", | ||||
{ | {"context": {"reason": str(e), "known_artifact": known_artifact,}}, | ||||
"context": { | |||||
"revision": hashutil.hash_to_hex(rev_id), | |||||
"reason": str(e), | |||||
"known_artifact": known_artifact, | |||||
} | |||||
}, | |||||
) | ) | ||||
# metadata field for the revision is not as expected by the loader | # metadata field for the revision is not as expected by the loader | ||||
# nixguix. We consider this not the right revision and continue checking | # nixguix. We consider this not the right revision and continue checking | ||||
# the other revisions | # the other revisions | ||||
return None | return None | ||||
def resolve_revision_from( | |||||
self, known_artifacts: Dict, p_info: NixGuixPackageInfo, | |||||
) -> Optional[bytes]: | |||||
for rev_id, known_artifact in known_artifacts.items(): | |||||
known_integrity = self._get_integrity_from_artifact(known_artifact, rev_id) | |||||
if p_info.integrity == known_integrity: | |||||
return rev_id | |||||
return None | |||||
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. | ||||
Note this repository is not loaded explicitly. So, this | Note this repository is not loaded explicitly. So, this | ||||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |